【问题标题】:Why does this orientation code not work?为什么这个方向代码不起作用?
【发布时间】:2012-02-26 05:03:33
【问题描述】:

我有一个简单的 UIWebView 嵌套在 ViewController 中,它以模态方式呈现在导航控制器之外。

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

所有视图都处理所有方向,除了上面有WebView的那个,它是通过配置来处理它的方向。

带有网页视图的控制器具有以下方向代码:

- (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 视图的模态。一旦发生这种情况,似乎整个应用程序的方向都被锁定了。所有其他视图随后都不会响应任何形式的旋转。

有什么想法吗?

谢谢

【问题讨论】:

  • orientationLandscape 到底是什么?它是字典中的键吗?
  • 这些是包裹在 NSNumber 中的布尔值。来自核心数据。

标签: iphone objective-c ios orientation


【解决方案1】:

这里有一些东西可以尝试。向 UIDevice 注册 UIDeviceOrientationDidChangeNotification 并告诉它开始生成通知。收到通知时,调用 UIViewController 类方法attemptRotationToDeviceOrientation(仅限iOS 5)。

阅读此技术说明也可能会有所帮助,因为您可能在这里做错了:https://developer.apple.com/library/ios/#qa/qa1688/_index.html

【讨论】:

  • 很棒的答案和很好的参考
【解决方案2】:

首先,确保在您的项目设置中单击支持的正确方向(目标 -> 应用名称 ->摘要)

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

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 2012-02-22
    • 2023-03-03
    • 2017-10-02
    • 2016-07-10
    • 2010-12-14
    • 2017-04-09
    • 2013-01-30
    • 2014-05-23
    相关资源
    最近更新 更多