框架根据界面方向

时间:2010-12-11 11:35:07

标签: iphone objective-c user-interface uiinterfaceorientation mobile-devices

我在UIAlertView中有一个UITextField。当方向改变时,我想更新UITextField的框架,因为它会与UIAlertView的按钮重叠。这些是框架:

portrait: CGRectMake(12.0, 45.0, 260.0, 26.0)
landscape: CGRectMake(12.0, 30.0, 260.0, 26.0)

如何直接使用加速计检查设备的方向是否已更改

它应该在-[UIViewController shouldAutorotateToInterfaceOrientation:]吗?

1 个答案:

答案 0 :(得分:2)

试试这个

if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight)
{
   //Landscape Frame
}
if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait)
{
   //Portrait Frame
}
相关问题