2011-08-04 49 views
4

我使用willRotateToInterfaceOrientation来检测旋转并根据方向移动项目。iOS - UIViewcontroller检测旋转?

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

解决方案是什么?

+0

您是否试图将其限制在某个方向?例如,以横向模式启动。 – rich

回答

1

我手动从我UIApplication检测UIInterfaceOrientation,和我手动叫willAnimateRotationToInterfaceOrientationviewDidAppear

2

您需要设置接口依据方位

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

,重复,对人的不同的设备取向

+1

实际上UIInterfaceOrientation是处理方向的正确方法 – aryaxt