我的iOS应用程序有两种不同的UI规格。
我面临以下情况的方向变更问题(颠倒不支持)。
仅供参考:我使用self.view.frame.size.width
设置用户界面的宽度以及使用UIDeviceOrientationDidChangeNotification
确定方向更改
1.改变方向到横向
2.改变方向颠倒(不设置任何框架)
3.直接改变肖像方向(纵向模式设置框)
在执行这些步骤后,我的UI框架错位。
我的纵向模式宽度为568。
请建议我一个更好的方法来解决这个问题。
答案 0 :(得分:1)
在旋转时更改self.view
框架并不是一个好习惯,因为bound
由UIViewController
旋转逻辑处理。
您可以使用willRotateToInterfaceOrientation:duration:
和didRotateFromInterfaceOrientation:
委托方法进行手动轮换。
答案 1 :(得分:1)
您列出了设备方向更改,您需要允许UI旋转并使用
进行收听- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//update your view's subviews
}
请注意,UIDeviceOrientation与UIInterfaceOrientation不同
允许界面旋转将此添加到视图控制器,并确保在项目plist中支持“支持的界面方向”键
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}