Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPercentDrivenInteractiveTransition cancelTransition turns screen black

Tags:

uikit

iphone

ios7

I'm implementing custom navigation transitions, and using UIPercentDrivenInteractiveTransition to do the trick.

I've got the noninteractive transition working fine, and I'm using an animation block to handle the transition animation, but once I added in interactive transitions, the screen now goes black if I cancel the transition.

Here's my code that tracks the gesture:

-(void)userDidPan:(UIScreenEdgePanGestureRecognizer *)recognizer {
        CGPoint location = [recognizer locationInView:nil];

    if (recognizer.state == UIGestureRecognizerStateBegan) {
        // We're being invoked via a gesture recognizer – we are necessarily interactive
        self.hasActiveInteraction = YES;
        self.interactiveTransition = [BXTPercentDrivenInteractiveTransition new];
        [[BXTNavigationController sharedNavigationController] popViewControllerAnimated:YES];
    }
    else if (recognizer.state == UIGestureRecognizerStateChanged) {
        CGFloat ratio = location.x / CGRectGetWidth(recognizer.view.frame);
        NSLog(@"Percentage complete: %0.2f",ratio*100);
        [self.interactiveTransition updateInteractiveTransition:ratio];
    }
    else if (recognizer.state == UIGestureRecognizerStateEnded) {
        // Depending on our state and the velocity, determine whether to cancel or complete the transition.
        CGFloat ratio = location.x / CGRectGetWidth(recognizer.view.frame);
        if (ratio > 0.50) {
            NSLog(@"Completing");
            [self.interactiveTransition finishInteractiveTransition];
        }
        else {
            NSLog(@"Canceling");
            [self.interactiveTransition cancelInteractiveTransition];
        }
    }
}

...and here's an (abbreviated) look at my animation block when popping off the view controller:

[UIView animateWithDuration:kBXTNavigationTimingDuration
                              delay:0
                            options:animationOption
                         animations:^{
                             toVC.view.frame = destinationFrameForPoppedView; 
                             fromVC.view.frame = CGRectOffset(fromVC.view.frame, fromVC.view.frame.size.width, 0);

                         } completion:^(BOOL finished) {
                             [darkeningView removeFromSuperview];
                             [_transition.secondaryTransitionViews enumerateObjectsUsingBlock:^(BXTTransitionView *transitionView, NSUInteger idx, BOOL *stop) {
                                 [transitionView.view removeFromSuperview];
                             }];

                             [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
                         }];

Any ideas why the screen goes black when cancelling a swipe-from-the-left pop animation with a custom navigation transition?

like image 674
bryanjclark Avatar asked Nov 01 '22 13:11

bryanjclark


1 Answers

Solved! I deleted all the removeFromSuperview calls in the animation completion block and it solved it (I had the same problem like you with almost the same code, see my comment to your q'). Try removing these lines from your code:

[darkeningView removeFromSuperview];
[_transition.secondaryTransitionViews enumerateObjectsUsingBlock:^(BXTTransitionView *transitionView, NSUInteger idx, BOOL *stop) {
    [transitionView.view removeFromSuperview];
}];
like image 127
Aviel Gross Avatar answered Nov 15 '22 04:11

Aviel Gross