1

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

-(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实现 aviewWillAppear:animatedviewWillDisappear: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主视图控制器在对象被推送之前和弹出动画之前立即消失并重新出现。

该文档不清楚是否willRotateToInterfaceOrientation:duration:以及didRotateFromInterfaceOrientation:应该在动画块中调用,但我怀疑他们不应该允许视图控制器为响应消息而对其更改进行动画处理。但是,如果它们落在动画块之外,主视图控制器有时会消失。

4

1 回答 1

2

动画无法正常工作,因为我从未调用viewWillLayoutSubviewsdidRotateFromInterfaceOrientation:

[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) {

                     }];
于 2013-10-23T06:42:25.067 回答