UISplitViewController 主细节控制器的动画可见性 [英] Animate visibility of master detail controller of UISplitViewController

查看:22
本文介绍了UISplitViewController 主细节控制器的动画可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 UISplitViewController 中,我希望主视图控制器仅在纵向或我的详细视图控制器未显示控制器类型时才允许显示,MyFullScreenViewController.我已经实现了 UISplitViewControllerDelegate 来适当地表明这一点.

In my UISplitViewController, I want the master view controller to only be allowed to display when in Portrait orientation or when my detail view controller is not displaying a type of controller, MyFullScreenViewController. I've implemented the UISplitViewControllerDelegate to indicate this appropriately.

-(BOOL)splitViewController:(UISplitViewController *)svc
  shouldHideViewController:(UIViewController *)vc
             inOrientation:(UIInterfaceOrientation)orientation
{
    if (UIInterfaceOrientationIsPortrait(orientation) ||
        [[self.navigationController topViewController] isKindOfClass:[MyFullScreenViewController class]])
    {
        return YES;
    }
    return NO;
}

然而,UISplitViewController 只在旋转期间调用委托.所以MyFullScreenViewController 实现了一个viewWillAppear:animatedviewWillDisappear:animated.

However, the UISplitViewController only invokes the delegate during rotation. So MyFullScreenViewController implements a viewWillAppear:animated and viewWillDisappear:animated.

- (void)viewWillAppear:(BOOL)animated
{
    [self fakeRotationOfSplitViewController];
    [super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [self fakeRotationOfSplitViewController];
    [super viewWillDisappear:animated];
}
-(void)fakeRotationOfSplitViewController
{
    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
    CGFloat duration = 1.0f;
    CGFloat fakeDuration = 0.0f;

    [UIView animateWithDuration:duration
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         [[self splitViewController] willAnimateRotationToInterfaceOrientation:orientation
                                                                                      duration:fakeDuration];
                         [[self splitViewController] willRotateToInterfaceOrientation:orientation
                                                                             duration:fakeDuration];
                         [[self splitViewController] didRotateFromInterfaceOrientation:orientation];
                     } completion:^(BOOL finished) {

                     }];

}

除了动画,一切正常.主视图控制器在 UINavigationController 对象推送之前和弹出动画之前立即消失并重新出现.

Everything works except the animation. The master view controller immediately disappears and reappears prior to the UINavigationController object's push and prior to the pop animation.

文档不清楚是否应该在动画块中调用 willRotateToInterfaceOrientation:duration:didRotateFromInterfaceOrientation:,但我怀疑它们不应该允许视图控制器动画它响应消息的变化.然而,如果它们落在动画块之外,主视图控制器有时会消失.

The documentation is unclear whether willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation: should be called within the animation block, but I suspect they shouldn't to allow the view controller to animate it changes in response to the message. However if they fall outside the animation block, the master view controller will sometimes disappear.

推荐答案

动画不起作用,因为我从未在 didRotateFromInterfaceOrientation: 之后调用 viewWillLayoutSubviews.

The animation was not working because I never called viewWillLayoutSubviews after didRotateFromInterfaceOrientation:.

[UIView animateWithDuration:duration
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         [[self splitViewController] willAnimateRotationToInterfaceOrientation:orientation
                                                                                      duration:fakeDuration];
                         [[self splitViewController] willRotateToInterfaceOrientation:orientation
                                                                             duration:fakeDuration];
                         [[self splitViewController] didRotateFromInterfaceOrientation:orientation];
                         [[self splitViewController] viewWillLayoutSubviews];
                         [[[self splitViewController] view] layoutSubviews];
                     } completion:^(BOOL finished) {

                     }];

这篇关于UISplitViewController 主细节控制器的动画可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆