过渡后iOS7 UIModalTransitionStyleFlipHorizo​​ntal弹跳

2020/11/25 01:31 · ios ·  · 0评论

我正在为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];

这似乎是一个UIKit错误。以下变通办法似乎可以为我解决问题。

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

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

(将其放置在您要转换的视图控制器)。

为了解决此问题,我使用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];
                    }];
}

要使用它,您只需检查您是否在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];

就我而言,我有一个自定义UINavigationController,其中定义了自定义过渡:我不必每次都这样做。

这似乎是一个UIKit错误。以下变通办法似乎可以为我解决问题。

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

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

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

dismissViewControllerAnimated (将其放置在您退出的视图控制器中):

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];

    [self.navigationController.navigationBar.layer removeAllAnimations];
}

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

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

    [self.view setNeedsLayout];
} 

我遇到了同样的问题,可以“解决它”(这不是解决问题的真正方法,但看起来不错:))。诀窍是使用pushViewController/popViewControllerUIView动画一起进行翻转的视图控制器这是呈现视图控制器的示例代码:

UIViewController *viewController = [[UIViewController alloc] init];
[UIView transitionWithView:self.navigationController.view 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromLeft 
                animations:^{
                   [self.navigationController pushViewController:viewController animated:NO];
                }
                completion:nil];

消除它:

[UIView transitionWithView:self.navigationController.view 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromRight 
                animations:^{
                   [self.navigationController popViewControllerAnimated:NO];
                }
                completion:nil];

如果您不希望navigationBar在推送的控制器上调用[self.navigationController setNavigationBarHidden:YES animated:NO]in viewWillAppear希望这种方法对您有所帮助。

对于呈现和呈现的视图控制器,我都有一个UITableViewController内部UINavigationController,均使用自动布局进行配置。我注意到其他答案并不能解决当前呈现的视图控制器的tableView垂直跳20磅的问题。

该解决方案解决了这个问题。

在呈现的视图控制器(由Ben Packard提出)中:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar.layer removeAllAnimations];
}

在呈现视图控制器中(如尘土飞扬所建议):

- (void)viewWillLayoutSubviews{
    if (self.navigationController.presentedViewController) {
        [self.navigationController.navigationBar.layer removeAllAnimations];
        [self.tableView.layer removeAllAnimations];
    }
    [super viewWillLayoutSubviews];
}

我也一样。实际起作用的是将样式更改为CoverVertical,看起来更加流畅。

本文地址:http://ios.askforanswer.com/guoduhouios7-uimodaltransitionstylefliphorizontaldantiao.html
文章标签: ,   ,   ,   ,  
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!

文件下载

老薛主机终身7折优惠码boke112

上一篇:
下一篇:

评论已关闭!