【发布时间】:2011-02-10 23:42:38
【问题描述】:
我正在努力获得一个 iPhone 应用程序,该应用程序几乎需要导航控制器堆栈中的每次推送或弹出来改变方向。
基本上第一个视图是纵向的,第二个是横向的,第三个是纵向的(是的,我知道这不太理想,但这就是设计,我必须实现它。
我在这里得到了各种建议....
How do I detect a rotation on the iPhone without the device autorotating?
Force portrait orientation on pushing new view to UINavigationViewController
Is there a documented way to set the iPhone orientation?
但没有完全成功。
设置链接到 3.1.2 我对上面链接文章的阅读似乎表明,如果我的纵向视图推送视图
然后该视图应显示为旋转为横向。发生的情况是它以“破碎”的肖像形式出现,然后在设备转动时正确旋转。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}
如果我将控制器弹出回我的纵向视图(其中有一个适当的 shouldAutoRotate...),那么它将保持在损坏的横向视图中,直到设备返回纵向。
我还尝试删除所有 shouldautorotate 消息,而是通过转换视图来强制旋转。这种方法有效,我发现通过移动状态栏(实际上隐藏在我的应用程序中)[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;,键盘会在需要时以正确的方向显示。
这种方法的问题在于,当您没有状态栏时,状态栏转换会变得奇怪而难看 - 每次更改都会在页面上隐约出现阴影。
所以。我错过了什么。
1) 我认为在 3.1.2(或可能更早的版本)中 shouldAutorotateToInterfaceOrientation 应该通过推动控制器来提供所需的方向,我错了吗?
2) 是否有另一种方法可以让键盘以正确的方向显示。
3) 未记录的 API 调用是否可行(请不要!)
【问题讨论】:
标签: iphone objective-c uiinterfaceorientation