dismissViewControllerAnimated自定义动画 [英] dismissViewControllerAnimated custom animation
问题描述
我正在尝试使用自定义动画调用dismissViewControllerAnimated,但是它似乎不起作用.
I am trying to call dismissViewControllerAnimated with a custom animation, but it does not seem to work.
当我以如下方式显示视图控制器时:
When I present the view controller like:
cameraUI = UIImagePickerController()
cameraUI.delegate = self
cameraUI.sourceType = UIImagePickerControllerSourceType.Camera
cameraUI.mediaTypes = [kUTTypeImage]
cameraUI.allowsEditing = false
cameraUI.showsCameraControls = false
var translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
cameraUI.cameraViewTransform = translate;
var scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
cameraUI.cameraViewTransform = scale;
var transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromLeft
self.view.window?.layer.addAnimation(transition, forKey: nil)
self.presentViewController(cameraUI, animated: false, completion: nil)
那很好.它可以正确滑入.
That works great. It slides in properly.
然后我将其消除:
var transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromRight
self.view.window?.layer.addAnimation(transition, forKey: nil)
cameraUI.dismissViewControllerAnimated(false, completion: nil)
它只是消失而没有动画.
It just disappears without animating at all.
有什么想法吗?
推荐答案
自定义呈现或关闭视图控制器时发生的动画的方式不是通过在其后提供过渡,而是通过定制实际的动画.给呈现的视图控制器一个实现animationControllerForPresentedController:presentingController:sourceController:
的transitioningDelegate
并
animationControllerForDismissedController:
.现在,动画控制器通过其animateTransition:
的实现来完全负责动画.
The way you customize the animation that occurs when presenting or dismissing a view controller is not by supplying a transition behind it, but by customizing the actual animation. Give the presented view controller a transitioningDelegate
that implements animationControllerForPresentedController:presentingController:sourceController:
and
animationControllerForDismissedController:
. Now the animation controller is in total charge of the animation, through its implementation of animateTransition:
.
这篇关于dismissViewControllerAnimated自定义动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!