我正在更新iOS 7的应用程序,我发现了一个奇怪的问题。我正在展示一个用UIViewController包装在UINavigationController中的UIModalTransitionStyleFlipHorizontal。
在iOS 6中,它工作得很好,但是在iOS 7中,导航条在转换后会反弹。这和状态栏有关吗?我已经将主导航条的半透明设置为NO。
在Info.plist中,基于视图控制器的状态栏外观设置为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];发布于 2013-09-19 19:41:05
这似乎是一个UIKit错误。下面的解决办法似乎为我解决了这个问题。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar.layer removeAllAnimations];
}(将其放在正在将转换为的视图控制器中)。
发布于 2013-11-01 18:04:38
为了解决这个问题,我使用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,其中定义了自定义转换:我不必每次都这样做。
发布于 2014-03-07 02:12:27
这似乎是一个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];
} https://stackoverflow.com/questions/18781519
复制相似问题