iOS-7-Custom-ModalViewController-Transitions icon indicating copy to clipboard operation
iOS-7-Custom-ModalViewController-Transitions copied to clipboard

UIModalPresentationCustom presentation style can only be used with an animator or with unanimated dismissals

Open magnett opened this issue 11 years ago • 1 comments

First of all thanks for this nice control! It save me a lot of time. Xcode gives me the above warning and i saw comments in your code about that "//I will fix it later." Did you by any chance find a way to fix it because my knowledge isn't enough for that...

magnett avatar Jul 29 '14 22:07 magnett

Not sure if you or anybody would be interested but I implemented the animationControllerForDismissedController by changing to the following in AnimatedTransitioning

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
    if (self.isPresenting)
        [self presentWithTransitionContext:transitionContext];
    else
        [self dismissWithTransitionContext:transitionContext];
}

- (void)dismissWithTransitionContext:(id <UIViewControllerContextTransitioning>)transitionContext {
    UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    [UIView animateWithDuration:0.25f animations:^{
        CGRect screenRect = [UIScreen mainScreen].bounds;
        fromVC.view.frame = CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height);
    } completion:^(BOOL finished) {
        [fromVC.view removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
}

- (void)presentWithTransitionContext:(id <UIViewControllerContextTransitioning>)transitionContext {
    UIView *inView = [transitionContext containerView];
    UIViewController *toVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController *fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    [inView addSubview:toVC.view];

    CGRect screenRect = [UIScreen mainScreen].bounds;
    toVC.view.frame = CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height);

    [UIView animateWithDuration:0.25f animations:^{
        toVC.view.frame = CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height);
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}

and obviously uncomment the code in TransitionDelegate

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init];
    controller.presenting = NO;
    return controller;
}

sandervandenbrink avatar Oct 28 '15 10:10 sandervandenbrink