2012-02-26 84 views
1

我有一个简单的UIWebView嵌套在ViewController中,它以模态方式从导航控制器中呈现。此导向代码为什么不起作用?

结构如下:TableViewController - > TableViewController - >模态(的WebView呈现) - >模态(选项,通过手势而呈现,页面卷曲)

所有视图处理所有的方向,除了一个与它的WebView,它是通过配置来处理它的方向。

与Web视图控制器具有以下方向代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    BOOL orientationSwitch = NO; 

    if([self.webApp.orientationLandscape boolValue] && 
     UIInterfaceOrientationIsLandscape(interfaceOrientation)) 
     orientationSwitch = YES; 

    if([self.webApp.orientationPortrait boolValue] && 
     UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
     orientationSwitch = YES; 

    return orientationSwitch; 
} 

现在的意图是,你可以设置一些选项,这就是如果认为应作出反应的方向变化。大多数情况下,它可以工作,但是我有一个模式弹出窗口,您可以选择关闭包含Web视图的模式。一旦发生这种情况,整个应用程序的方向似乎都被锁定了。所有其他意见随后不会对任何形式的轮换作出响应。

任何想法?

谢谢

+0

什么是orientationLandscape?它是字典的关键吗? – CodaFi 2012-02-26 05:32:12

+0

这些都是包裹在NSNumber中的布尔值。来自核心数据。 – Slappy 2012-02-26 21:13:37

回答

3

这里有一些尝试。向UIDevice注册UIDeviceOrientationDidChangeNotification并告诉它开始生成通知。当有通知进来时,调用UIViewController类的方法attemptRotationToDeviceOrientation(仅适用于iOS 5)。

而且它可以帮助阅读本技术说明,因为您可能做错了什么:https://developer.apple.com/library/ios/#qa/qa1688/_index.html

+0

梦幻般的答案和很好的参考 – Slappy 2012-02-29 00:54:33

0

首先,请确保您的项目设置是正确的支撑取向点击(目标 - >应用程序的名字 - >摘要)

我不知道为什么会发生这种情况,但不久前我有类似的问题。很久以前,ios 3.2还是什么的。我创建了一个ViewRotatorController,它只实现了-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {} 方法。每个其他ViewControllers都继承这一点。让你的w​​ebappview有一个这样的其他实现。这可能不是最好的解决方案,但它应该工作。

相关问题