iOS - UIViewcontroller检测旋转?
问题描述:
我使用willRotateToInterfaceOrientation
来检测旋转并根据方向移动项目。iOS - UIViewcontroller检测旋转?
问题是,当页面第一次加载这个方法不会被调用,所以它不会尝试将对象移动到正确的位置?
解决方案是什么?
答
我手动从我UIApplication
检测UIInterfaceOrientation
,和我手动叫willAnimateRotationToInterfaceOrientation
上viewDidAppear
答
您需要设置接口依据方位
if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
// do something
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
// do something else
}
,重复,对人的不同的设备取向
+1
实际上UIInterfaceOrientation是处理方向的正确方法 – aryaxt
您是否试图将其限制在某个方向?例如,以横向模式启动。 – rich