我正在使用UIViewControllerTransitioningDelegate
在两个视图控制器(从 a MKMapView
)到基于 ( AVFoundation
) 构建的自定义相机之间构建自定义转换。一切都很顺利,直到我打电话presentViewController
,电话似乎挂了大约 1 秒钟(当我注销所有内容时)。当我转换到一个更简单的视图时,这甚至似乎发生了(我有一个只显示 a 的视图控制器,UITextview
即使在实际调用转换之前似乎有大约 0.4 - 0.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];
}];
}
任何帮助是极大的赞赏。