小编DaN*_*aNY的帖子

在容器视图控制器中旋转UIPageViewController

我有一个包含其他ViewControllers的UIViewController.初始ViewController在viewDidLoad中设置:

FirstViewController *first = [FirstViewController alloc] init];
first.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
first.view.frame = m_content.frame;

[self addChildViewController:first];
[m_content.view addSubview:first.view];
[first didMoveToParentViewController:self];
m_activeViewController = first;
Run Code Online (Sandbox Code Playgroud)

此Container Controller已实现automaticForwardAppearanceAndRotationMethodsToChildViewControllers返回YES.它还实现了手动将旋转更改转发到非活动ViewControllers

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    for(UIViewController *vc in m_viewControllers)
    {
        if(vc != [m_activeViewController]
            [vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    for(UIViewController *vc in m_viewControllers)
    {
        if(vc != [m_activeViewController]
            [vc didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    }
}
Run Code Online (Sandbox Code Playgroud)

当点击菜单按钮时,我在ViewControllers之间进行转换.

- (void)onMenuItemTapped:(id)sender
{
    UIViewController *vc = [m_viewControllers objectAtIndex:sender.tag];

    vc.view.frame = m_content.frame;
    [self addChildViewController:vc]; …
Run Code Online (Sandbox Code Playgroud)

containers screen-rotation uipageviewcontroller

6
推荐指数
1
解决办法
3561
查看次数