Domanda

I'm trying to build a custom transition in iOS 7. The transition occurs fine, but then when transition context complete transition the modal screen disappears from the view entirely. I've followed several tutorials and I don't see what I am doing wrong. In addition, if I don't call "complete transition" then the view stays, but will not receive any touch events. I checked in Reveal App and there is no view sitting on top of it. Any ideas?

Here is the method where I initiate the transition

- (IBAction)settingsButtonClicked:(id)sender
{
    UINavigationController *navigationController =[[self storyboard] instantiateViewControllerWithIdentifier:@"SettingsNavigationViewController"];
    navigationController.transitioningDelegate = self;
    [self presentViewController:navigationController animated:YES completion:nil];
}

Here is the code for the custom transition:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:toViewController.view];

    CGRect sourceRect = [transitionContext initialFrameForViewController:fromViewController];
    CGRect initialTargetFrame = [transitionContext initialFrameForViewController:toViewController];

    CGRect initialFrame = CGRectMake(sourceRect.size.width + initialTargetFrame.size.width, 0, initialTargetFrame.size.width, initialTargetFrame.size.height);
    CGPoint destinationPoint = CGPointMake(sourceRect.size.width - 500, 0);

    CGAffineTransform translate = CGAffineTransformMakeTranslation(initialFrame.origin.x, initialFrame.origin.y);
    toViewController.view.transform = translate;



    [UIView animateWithDuration:PRESENT_DURATION delay:0 options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         toViewController.view.transform = CGAffineTransformMakeTranslation(destinationPoint.x, destinationPoint.y);
                     }
                     completion:^(BOOL completed) {
                         if (completed) {

                             [transitionContext completeTransition:!transitionContext.transitionWasCancelled];
                         }

                     }];
}
È stato utile?

Soluzione

So I found out what I was doing wrong. I was changing the modalPresentationStyle to custom on the view controller that was being popped onto the navigation controller when I should have been setting it on the navigation controller itself. I added this line to the settingsButtonClicked method above and it worked properly.

navigationController.modalPresentationStyle = UIModalPresentationCustom;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top