5

I am using UIViewControllerTransitioningDelegate to build custom transitions between two view controllers (from a MKMapView) to a custom Camera built on (AVFoundation). Everything goes well until I call the presentViewController and the phone seems to hang for about 1 second (when I log everything out). This even seems to happen when I am transitioning to a much simpler view (I have a view controller that only displays a UITextview and even with that there appears to be about a .4 - .5 second delay before the transition is actually called).

This is currently how I am calling the transition

 dispatch_async(dispatch_get_main_queue(), ^{
        UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        CameraViewController *cvc2 = [sb instantiateViewControllerWithIdentifier:@"Camera"];

        cvc2.modalPresentationStyle = UIModalPresentationFullScreen; // Needed for custom animations to work
        cvc2.transitioningDelegate = self; //Conforms to the UIViewControllerTransitioningDelegate protocol
        [self presentViewController:cvc2 animated:YES completion:nil];
    });

Here is my animateTransition method for that call. Very straight forward and currently the view that is presenting this only has a MkMapView on it (no additional views or methods).

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {

if (self.type == MapAnimationTypePresent) {//From map to another view

    UIView *containerView = [transitionContext containerView];
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

// Amazing category for iOS 7 compatibility found here - http://stackoverflow.com/a/25193675/2939977 
    UIView *toView = [toViewController viewForTransitionContext:transitionContext];
    UIView *fromView = [fromViewController viewForTransitionContext:transitionContext];

    toView.frame = self.view.frame;
    fromView.frame = self.view.frame;

    //Add 'to' view to the hierarchy
    toView.alpha = 0;
    [containerView insertSubview:toView aboveSubview:fromView];

    [UIView animateWithDuration:.5 animations:^{

        toView.alpha = 1;

    }completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}

Any help is greatly appreciated.

Chase S
  • 448
  • 3
  • 20
  • 3
    I don't have a solution for you, but I can confirm that I'm also seeing cases where presentViewController is inexplicably hanging in iOS 8 at the exact point you describe, where it didn't in iOS 7. In my case I am calling presentViewController in a didSelectRow delegate callback of a UITableView. I added a dispatch_async to the main queue around the presentViewController call and that fixed my issue. Looks like that didn't do the trick here. One other note is that I've confirmed that there is no significant CPU usage when the hang/delay occurs. – Matt R Nov 11 '14 at 20:28
  • @MattR Thanks for the thoughts Matt. The CPU usage as far as I can tell is fine. I even tried doing the same transition on a brand new blank project and I am still seeing the same lag. Haven't really found a solution yet. – Chase S Nov 12 '14 at 21:21
  • I've found that this still is a problem in iOS9. When animating the alpha value the animation appears laggy. – Groot Jan 07 '16 at 09:43

0 Answers0