iOS5打破了UISplitViewController的回调,如何手动调用?

在SO的其他问题中也有 been reported,iOS 5会更改如何根据本发行说明发送拆分视图控制器的循环回调.这不是一个笨蛋(我想),因为我没有找到另一个问题,关于如何调整iOS 5中的分割视图控制器使用情况来应对这种变化:

Rotation callbacks in iOS 5 are not applied to view controllers that
are presented over a full screen. What this means is that if your code
presents a view controller over another view controller,and then the
user subsequently rotates the device to a different orientation,upon
dismissal,the underlying controller (i.e. presenting controller) will
not receive any rotation callbacks. Note however that the presenting
controller will receive a viewWillLayoutSubviews call when it is
redisplayed,and the interfaceOrientation property can be queried from
this method and used to lay out the controller correctly.

在我的根拆分视图控制器中配置弹出按钮时遇到困难(当您在纵向显示控制器时应该显示在弹出窗口中的左窗格视图).以下是我的应用程序启动顺序在设备处于横向模式时用于iOS 4.x的工作原理:

>使用[window addSubview:splitViewController.view]将分割视图控制器安装到窗口中; [window makeKeyAndVisible] ;.这将导致splitViewController:willHideViewController:withBarButtonItem:forPopoverController:即使设备已经处于横向模式,也在代理上调用(即模拟横幅 – >纵向旋转).
>提供一个全屏模式(我的加载屏幕),它完全覆盖了下面的分割视图.
>完成加载和关闭加载屏幕模态.由于设备处于横向模式,因为拆分视图控制器被显示,这将导致splitViewController:willShowViewController:invalidatingBarButtonItem:在代理上调用(即模拟纵向 – >横向旋转),从而使条形按钮项无效,删除它从分裂视图的右侧,离开我们想要的地方.万岁!

所以,问题是因为发行说明中描述的变化,不管iOS 4.3内部发生什么,导致splitViewController:willShowViewController:invalidatingBarButtonItem:被调用不再发生在iOS 5中.我尝试子类化UISplitViewController,以便我可以提供一个自定义根据发行说明建议执行viewWillLayoutSubviews,但我不知道如何重现iOS 4触发的内部事件所需的顺序.我试过这个:

- (void) viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    UINavigationController *rightStack = [[self viewControllers] objectAtIndex:1];
    UIViewController *rightRoot = [[rightStack viewControllers] objectAtIndex:0];
    BOOL rightRootHasButton = ... // determine if bar button item for portrait mode is there

    // iOS 4 never goes inside this 'if' branch
    if (UIInterfaceOrientationIsLandscape( [self interfaceOrientation] ) &&
        rightRootHasButton)
    {
        // Manually invoke the delegate method to hide the popover bar button item
        [self.delegate splitViewController:self
                    willShowViewController:[[self viewControllers] objectAtIndex:0]
                 invalidatingBarButtonItem:rightRoot.navigationItem.leftBarButtonItem];
    }
}

这主要是工作,但不是100%.问题是自己调用委托方法实际上并不会使条按钮项无效,所以首次旋转为纵向时,系统认为条形按钮项目仍然正确安装,并且不会尝试重新安装.只有在您再次旋转到风景之后,然后回到纵向系统才能恢复到正确的状态,并且实际上会以纵向模式安装弹出式窗口按钮.

基于this question,我还尝试手动调用所有的旋转回调,而不是触发委托方法,例如:

// iOS 4 never goes inside this 'if' branch
if (UIInterfaceOrientationIsLandscape( [self interfaceOrientation] ) &&
    rightRootHasButton)
{
    [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
    [self willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:0];
    [self didRotateFromInterfaceOrientation:self.interfaceOrientation];
}

然而,这似乎是导致无限循环回到viewWillLayoutSubviews

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...