iOS7 UIModalTransitionStyleFlipHorizo​​ntal在转换后反弹

Ren*_*ene 73 cocoa-touch uiviewcontroller uinavigationcontroller ios uimodaltransitionstyle

我正在为iOS 7更新我的应用程序,我发现了一个奇怪的问题.我正在展示一个包含在UINavigationController中的UIViewController UIModalTransitionStyleFlipHorizontal.

在iOS 6中它工作正常,但在iOS 7中,导航栏在转换后反弹.这与状态栏有关吗?我已将主导航栏的半透明度设置为NO.

在Info.plist中,基于View控制器的状态栏外观设置为NO.

这是一个GIF,在最小的演示应用程序中显示问题:

在此输入图像描述

这是我的代码:

feedNavigationController = [[UINavigationController alloc] init];
feedNavigationController.navigationBar.translucent = NO;

SettingsViewController *settingsVC = [[SettingsViewController alloc] init];

feedNavigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[feedNavigationController setViewControllers:[NSArray arrayWithObjects:settingsVC, nil]];

[self presentViewController:feedNavigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

Ben*_*ard 54

这似乎是一个UIKit错误.以下解决方法似乎为我解决了这个问题.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}
Run Code Online (Sandbox Code Playgroud)

(将其放在要转换的视图控制器).

  • 这适用于我的演示,但不解雇. (12认同)
  • 这对我来说是*第一次调用动画的时间,但在任何后续调用中都没有.为什么会这样,因为每次视图出现时都会调用它?郁闷了. (5认同)

Eri*_*icD 16

为解决现在和解雇这个问题,我使用iOS7自定义转换.

将其添加到您的UIViewController:

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    return (id<UIViewControllerAnimatedTransitioning>)self;
}

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return (id<UIViewControllerAnimatedTransitioning>)self;
}

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
    return 0.7f;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    UIView *containerView = [transitionContext containerView];


    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    [containerView addSubview:fromVC.view];

    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [containerView addSubview:toVC.view];

    UIViewAnimationOptions animationOption = ([toVC.presentedViewController isEqual:fromVC])?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;


    [UIView transitionFromView:fromVC.view
                        toView:toVC.view
                      duration:[self transitionDuration:transitionContext]
                       options:animationOption
                    completion:^(BOOL finished) {
                        [transitionContext completeTransition:YES];
                    }];
}
Run Code Online (Sandbox Code Playgroud)

要使用它,您只需检查您是否在iOS7上并设置transitionDelegate:

YourVCWithTheCustomTransition* yourVC = [[YourVCWithTheCustomTransition alloc] init];

CGFloat deviceVersion = [UIDevice currentDevice].systemVersion.floatValue;
if(deviceVersion >= 7.0) [yourVC setTransitioningDelegate:yourVC];

[self presentModalViewController:yourVC animated:YES];
[yourVC release];
Run Code Online (Sandbox Code Playgroud)

在我的例子中,我有一个自定义UINavigationController,其中定义了自定义转换:我不必每次都这样做.

  • [不检查系统版本](http://triplesoftware.nl/2014/02/checking-device-or-system-version/)但检查方法是否可用:`if([yourVC respondsToSelector:@ selector(setTransitioningDelegate :)] {[yourVC setTransitioningDelegate:yourVC];}` (3认同)

dus*_*sty 9

这似乎是一个UIKit错误.以下解决方法似乎为我解决了这个问题.

presentViewController (将其放在要转换的视图控制器中):

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}
Run Code Online (Sandbox Code Playgroud)

dismissViewControllerAnimated (将其置于您忽略的视图控制器中):

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}
Run Code Online (Sandbox Code Playgroud)

如果你不使用autolayout.您需要将此添加到视图控制器dismiss中:

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    [self.view setNeedsLayout];
} 
Run Code Online (Sandbox Code Playgroud)