1

UIPageViewController如果用户浏览到不支持当前界面方向的新视图控制器,我正在尝试让设备旋转。我想获得或多或少相同的行为,就像以模态方式推送 VC 一样。

示例:当前 VCUIPageViewController支持所有界面方向,用户浏览到下一个 VC,该 VC 应仅以横向显示。

我使用默认的Page-Base-Application-Template进行测试,实现shouldAutorotateToInterfaceOrientation了DataViewController的方法如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return YES;
    }

    if ([self.dataObject isEqualToString:@"February"]) {
        return NO;
    }

    return YES;
}

我的期望是,如果我在 2 月浏览视图控制器,屏幕将旋转为横向,但仍保持纵向。有趣的是,shouldAutorotateToInterfaceOrientation如果我浏览到 2 月的 VC,则会调用并返回 NO。

我也尝试过检查方向,RootViewController但没有任何运气。

我现在没有任何想法。任何建议将不胜感激,谢谢!

4

1 回答 1

0

The interesting part is that the shouldAutorotateToInterfaceOrientation is called and NO is returned if I skim to the february-VC

In that case I would suggest that your only approach will be to subclass UIPageViewController. Clearly it knows what it thinks the reply to shouldAutorotate should be, and you disagree with that reply, so you'll need to offer a different reply.

I am not surprised to hear that UIPageViewController behaves like this, though - after all, UINavigationController works the same way: if you push a view controller onto the navigation controller's stack and that view controller does not permit the current orientation of the device, the interface does not rotate to an orientation that the view controller does permit. I work around that by presenting a view (what used to be called a modal view), which does force the device to rotate.

于 2011-12-22T16:31:23.117 回答