Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS-UIViewcontroller是否检测旋转?_Iphone_Objective C_Ios_Uiviewcontroller_Orientation - Fatal编程技术网

Iphone iOS-UIViewcontroller是否检测旋转?

Iphone iOS-UIViewcontroller是否检测旋转?,iphone,objective-c,ios,uiviewcontroller,orientation,Iphone,Objective C,Ios,Uiviewcontroller,Orientation,我正在使用willRotateToInterfaceOrientation检测旋转并根据方向移动项目 问题是当页面第一次加载时,这个方法没有被调用,所以它没有尝试将对象移动到正确的位置 解决方案是什么?您需要根据方向设置界面 if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) { // do something } else if ([UIDevice currentDevice].orie

我正在使用
willRotateToInterfaceOrientation
检测旋转并根据方向移动项目

问题是当页面第一次加载时,这个方法没有被调用,所以它没有尝试将对象移动到正确的位置


解决方案是什么?

您需要根据方向设置界面

if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait)  {
     // do something
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
     // do something else
}

然后重复,对于所有不同的设备方向,我从我的
ui应用程序中手动检测到
ui接口定向
,并且我在
视图上手动调用
willanimaterotationInterfaceoOrientation
是否尝试将其限制在某个方向?例如,让它以横向模式启动。实际上,UIInterfaceOrientation是处理方向的正确方法