在运行时为不同方向设置帧的首选方法

时间:2014-05-21 07:51:35

标签: ios frame screen-orientation uiinterfaceorientation orientation-changes

我的iOS应用程序有两种不同的UI规格。
我面临以下情况的方向变更问题(颠倒不支持)。

仅供参考:我使用self.view.frame.size.width设置用户界面的宽度以及使用UIDeviceOrientationDidChangeNotification确定方向更改

1.改变方向到横向
2.改变方向颠倒(不设置任何框架)
3.直接改变肖像方向(纵向模式设置框)

在执行这些步骤后,我的UI框架错位。
我的纵向模式宽度为568。

请建议我一个更好的方法来解决这个问题。

2 个答案:

答案 0 :(得分:1)

在旋转时更改self.view框架并不是一个好习惯,因为boundUIViewController旋转逻辑处理。

您可以使用willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation:委托方法进行手动轮换。

答案 1 :(得分:1)

您列出了设备方向更改,您需要允许UI旋转并使用

进行收听
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    //update your view's subviews
}

请注意,UIDeviceOrientation与UIInterfaceOrientation不同

允许界面旋转将此添加到视图控制器,并确保在项目plist中支持“支持的界面方向”键enter image description here

中的横向和纵向
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}