问题
I have found a strange issue while debugging on iOS 9. In my View Controller's viewDidLoad
I have this piece of code:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
When I am pushing or popping a new view controller I have noticed a strange animation. The transition isn't smooth and it seems like it is displaying a "stack" of view controllers (you can notice the top and even slightly a bottom of both images).
I had no problem on iOS 7 or iOS8, is this a bug of the newly released iOS 9 or am I missing something?
It's also worth to mention that I am using custom animation for push/pop view controller transition.
Here is an example of one of the overriden UINavigationController
methods
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIView *theWindow = self.view;
[[theWindow layer] removeAllAnimations];
if (animated) {
CATransition *animation = [CATransition animation];
[animation setDuration:0.25];
[animation setType:kCATransitionFade];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[[theWindow layer] addAnimation:animation forKey:@""];
}
[super pushViewController:viewController animated:NO];
}
EDIT:
I have been debugging this issue for couple of hours now. I have reimplemented the custom animations following API for view controllers transitions introduced in iOS 7 (navigationController:animationControllerForOperation:operation fromViewController:toViewController
) but the issue persists.
The problem happens if the transition is animating alpha
property.
Do you have an idea how to overcome this issue?
Thanks.
回答1:
You need to setup final frame for toViewController. transitionContext.finalFrame(for:)
can help you to determine it. Something like:
toViewController.view.frame = transitionContext.finalFrame(for: toViewController)
来源:https://stackoverflow.com/questions/32700122/ios-9-push-pop-view-controller-broken-by-edgesforextendedlayout