较慢的presentViewController性能
我正在使用UIViewControllerTransitioningDelegate
在两个视图控制器(从MKMapView
)到build立在( AVFoundation
)上的自定义相机之间构build自定义转换。 一切顺利,直到我打电话给presentViewController
和手机似乎挂起约1秒(当我login一切了)。 这甚至在我转换到一个更简单的视图(我有一个视图控制器只显示一个UITextview
,甚至在实际调用转换之前似乎有大约.4 – .5秒的延迟)时发生。
目前我正在调用这个过渡
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]; });
这是我为那个调用animateTransition
方法。 非常简单直观,目前只有一个MkMapView
视图(没有额外的视图或方法)。
-(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]; }]; }
任何帮助是极大的赞赏。