UIPercentDrivenInteractiveTransition cancel does not finish/cancel animation smoothly when presenting a modal view controller
| Originator: | Jake.Kirshner | ||
| Number: | rdar://14627659 | Date Originated: | 01-Aug-2013 07:02 PM |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.0b4 |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
Using a UIPercentDrivenInteractiveTransition that conforms to the UIViewControllerAnimatedTransitioning protocol does not animate smoothly after calling finishInteractiveTranstion or cancelInteractiveTransition when presenting a modal view controller when using the [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 options:0 animations completion] in animateTransition.
Steps to Reproduce:
create a custom UIPercentDrivenInteractiveTransition<UIViewControllerAnimatedTransitioning> object and use it from a modal view controller's transitioning delegate that will be presented with [_menuVC presentViewController:detailVC animated:YES completion:nil]; to drive a interactive transition from a pan gesture. calling finishinteractivetransition or cancelinteractivetransition after the gesture is complete causes the view to finish animating instantly (either by returning to the original view controller or presenting the new view controller) instead of smoothly finishing the transition.
Expected Results:
I would expect the animation to finish smoothly.
Actual Results:
The animation finishes instantly as if it were called with a presentViewController animated:NO call.
Regression:
I think beta 2 didn't have this problem, but its definitely been a bug since 7.0 beta 3
Notes:
ANIMATE TRANSITION:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *menuVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *detailVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *transitionView = [transitionContext containerView];
UIView *detailView = detailVC.view;
UIView *menuView = menuVC.view;
CGRect transitionRect = [transitionContext initialFrameForViewController:menuVC];
CGRect detailStart = transitionRect;
detailStart.origin.x = CGRectGetWidth(transitionRect);
CGRect detailEnd = transitionRect;
detailView.frame = detailStart;
CGRect menuStart = transitionRect;
CGRect menuEnd = transitionRect;
menuEnd.origin.x = -1 * (CGRectGetWidth(transitionRect) / 4);
menuView.frame = menuStart;
[transitionView addSubview:menuView];
[transitionView insertSubview:detailView
aboveSubview:menuView];
[UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 options:0 animations:^{
detailView.frame = detailEnd;
menuView.frame = menuEnd;
} completion:^(BOOL finished) {
BOOL completeTransition = !([transitionContext transitionWasCancelled]);
[transitionContext completeTransition:completeTransition];
}];
}
TRANSITION OUTLET:
- (IBAction)transitionGestureChanged:(UIPanGestureRecognizer *)sender {
if ([sender state] == UIGestureRecognizerStateBegan) {
_startPosX = [sender locationInView:sender.view].x;
_isInteractive = YES;
UIViewController *detailVC = [_menuVC.storyboard instantiateViewControllerWithIdentifier:_menuVC.currentDetailViewIdent];
[_menuVC presentViewController:detailVC animated:YES completion:nil];
}
else if ([sender state] == UIGestureRecognizerStateChanged) {
CGFloat locationInContainerView = [sender locationInView:[[_menuVC transitionCoordinator] containerView]].x;
if (fabsf(_startPosX) == 0) {
_startPosX = locationInContainerView;
}
else {
CGFloat percentComplete = (_startPosX - locationInContainerView) / 300;
percentComplete = MAX(0, percentComplete);
percentComplete = MIN(1, percentComplete);
[self updateInteractiveTransition:percentComplete];
}
}
else {
_startPosX = 0;
_isInteractive = NO;
if ([sender velocityInView:sender.view].x < 0) {
[self finishInteractiveTransition];
}
else {
[self cancelInteractiveTransition];
}
}
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!