Eliminate custom animation
I am trying to call rejectViewControllerAnimated with a custom animation but it doesn't seem to work.
When I present a 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)
This works great. It slides correctly.
Then I go to dismiss it:
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 with no animation at all.
Any thoughts?
source to share
How you customize the animation that occurs when the view controller is displayed or is disabled is not navigated behind it, but by customizing the actual animation. Give the presented controller a view transitioningDelegate
that implements animationControllerForPresentedController:presentingController:sourceController:
and
animationControllerForDismissedController:
. The animation controller is now in full animation charge, via the implementation animateTransition:
.
source to share