【问题标题】:Landscape/Portrait conflict - iOS横向/纵向冲突 - iOS
【发布时间】:2010-10-25 18:49:41
【问题描述】:

就在我以为我已经弄清楚了一切时..我遇到了这个问题。

场景。

我有一个简单的 tableView。并在导航项的 titleView 中有一个搜索栏。 SearchBar 通过视图控制器工具栏中的 uibarbuttonitem 添加到 navItems titleView。

现在,正常

使用 [beginResponder] 启动搜索栏后,键盘会出现。它会发出一个通知“KeyboardDidShow”,我在这里计算 UIKeyboard 的高度并相应地设置 tableView 的高度(缩短它)。

ON Rotation - 来回横向/纵向,一切正常。 -(void)didRotateInferfaceOrientation 被调用,一切都很好。

问题来了。

当键盘处于活动状态时,它有一个谷歌“搜索”按钮,这会推送到一个新视图 - webviewcontroller。

问题是,这个

当 [PORTRAIT]ViewController [SearchBar with keyboard active] --> 点击 Search --> [Portrait]WebViewController --> 将设备方向更改为 [Landscape] --> [Landscape]WebViewController 更改为横向 --- > 问题出在这里,用户点击返回 uiViewController[Landscape]

方法 -didRotatefromInterfaceOrientation 未被调用。不知何故,tableView 的高度搞砸了。虽然视图完美旋转。

这里有什么我缺少的吗..

将不胜感激。 .谢谢

【问题讨论】:

    标签: iphone interface ios orientation device


    【解决方案1】:

    当用户点击返回时,-didRotatefromInterfaceOrientation 将不会被调用。您需要在 viewWillAppear 中检查方向(或调用 viewDidLoad,在从背面点击返回之前),然后为所选方向调用正确的布局。

    在您的所有 (BOOL)shouldRotate... 方法中,您应该调用一个单独的方法以确保您的布局对于设备方向是正确的。

    【讨论】:

    • 你的意思是有一个用于定位目的的方法,然后每次在 ViewDidLoad 和 viewWillAppear 上调用它??
    • 有一个用于定位目的的方法,并且每次都调用它 -BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 被调用。
    【解决方案2】:

    我最近在我的一个应用程序中遇到了类似的问题,不完全是我们的问题,但不要打扰,你应该看到我的目标:我想简单地旋转使用 presentModalViewController 显示的 viewController...不幸的是它并没有真正起作用,尤其是在 iOS 4 之前的 OS 的旧 iPhone 上......所以我需要以编程方式旋转!只需获取您的屏幕尺寸,使用 CGAffineTransform 或类似的东西并更改尺寸,然后您应该完成... 如果您有兴趣,我可以发布一堆代码,请告诉我!

    编辑:

    UIScreen *screen = [UIScreen mainScreen];
            myController.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - 20);
            if(currentOrientation == UIDeviceOrientationLandscapeRight){
                myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(-90)));
    
            }else{
                myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
    
            }
            myController.view.center = window.center;
            [[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation];
            [self.window addSubview:self.tabBarController.view];
            [self.window bringSubviewToFront:self.tabBarController.view];
            [self.window addSubview:myController.view];
            [self.window bringSubviewToFront:myController.view];
            [self.tabBarController.view removeFromSuperview];`
    

    这还包括在旋转到横向时移除 TabBar 以获得更多空间...享受吧:)

    【讨论】:

    • 如果你能在那里扔一些代码我肯定会感兴趣的:)
    • 我编辑了我以前的帖子,所以请看一下并告诉我它是否符合您的需求,否则我可以提出其他建议:D
    【解决方案3】:

    您可以在 viewWillAppear 上手动调用 didRotateFromInterfaceOrientation 并自己传递一个方向(即 [UIApplication sharedApplication].statusBarOrientation)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多