【发布时间】:2014-08-11 12:28:04
【问题描述】:
在UIViewController 旋转方法中,我在执行设备旋转时遇到问题
方法内部
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
我得到的值不正确
根据文档:
在用户界面开始之前发送到视图控制器 旋转。子类可以重写此方法以执行额外的 轮换前的动作。例如,您可以使用 此方法用于禁用视图交互、停止媒体播放或 暂时关闭昂贵的绘图或实时更新。你也可能 使用它将当前视图交换为反映新视图的视图 界面方向。 当这个方法被调用时, interfaceOrientation 属性仍然包含视图的原始 方向。你的这个方法的实现必须调用 super at 在执行过程中的某个时间点。这个方法被调用,不管 您的代码是执行一步还是两步旋转。
我正举起设备(在启动应用程序后设备物理上处于纵向模式) - 所有视图都正确对齐纵向模式
但是在方法中我得到了错误的值:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// getting the wrong interface orientation here!!!!
// just checking the current orientation for debug
UIInterfaceOrientation currentOrientation = self.interfaceOrientation;
// the first time the device is rotated getting this value for current orientation:
// currentOrientation == UIInterfaceOrientationLandscapeRight
}
比这种奇怪的错误方向更糟糕的情况是在“将旋转到界面方向”的相同方法中,当前界面方向和目标界面方向相同,即:
self.interfaceOrientation === toInterfaceOrientation
那么框架调用这个方法的意义何在???
这会导致我的所有 UIView 放置代码在设备初始旋转时都无法正确计算。
为什么这个标志设置不正确?!?!
附言
第二次旋转设备后 - 标志设置正确,视图“对齐”自身正确。
【问题讨论】:
标签: ios objective-c uiviewcontroller uiinterfaceorientation