dismissViewControllerAnimated自定义动画

时间:2014-11-09 23:07:39

标签: ios objective-c xcode swift

我试图用自定义动画调用dismissViewControllerAnimated,但它似乎不起作用。

当我呈现视图控制器时:

        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)

这很有效。它适当滑入。

然后我去解雇它:

            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)

它完全没有动画就消失了。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

在呈现或关闭视图控制器时自定义动画的方式不是通过提供它后面的转换,而是通过自定义实际动画。为呈现的视图控制器提供实现transitioningDelegateanimationControllerForPresentedController:presentingController:sourceController:的{​​{1}} animationControllerForDismissedController:。现在,动画控制器通过其animateTransition:的实现来完全控制动画。