简体   繁体   English

iOS - UIViewcontroller检测旋转?

[英]iOS - UIViewcontroller detect rotation?

I am using willRotateToInterfaceOrientation to detect rotation and move items according to the orientation. 我正在使用willRotateToInterfaceOrientation来检测旋转并根据方向移动项目。

The problem is that when the page first loads this method doesn't get called so it doesn't try to move the objects to the correct location? 问题是,当页面首次加载时,此方法不会被调用,因此它不会尝试将对象移动到正确的位置?

What is the solution? 解决办法是什么?

You need to setup the interface according to the orientation 您需要根据方向设置界面

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

And repeat that for al the different device orientations 并为不同的设备方向重复这一点

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM