如何使用预先存在的动画为视图设置动画?

时间:2017-09-29 04:32:33

标签: ios uiviewanimation

我想使用UIView的预先存在的动画为视图设置动画。 我正在使用此代码为UIView设置动画 -

return LocalRedirect(returnUrl);

我想动画一些其他视图,以及这个动画。

3 个答案:

答案 0 :(得分:0)

您需要做的是链接您的动画。以下是Apple的示例。

let fadeOut = CABasicAnimation(keyPath: "opacity")
fadeOut.fromValue = 1
fadeOut.toValue = 0
fadeOut.duration = 1

let expandScale = CABasicAnimation()
expandScale.keyPath = "transform"
expandScale.valueFunction = CAValueFunction(name: kCAValueFunctionScale)
expandScale.fromValue = [1, 1, 1]
expandScale.toValue = [3, 3, 3]

let fadeAndScale = CAAnimationGroup()
fadeAndScale.animations = [fadeOut, expandScale]
fadeAndScale.duration = 1

答案 1 :(得分:0)

您可以使用以下基本iOS动画:  UIView .animate(withDuration:TimeInterval){         代码
        }

在代码段中,您可以编写以更改不同视图的x位置。每当您点击按钮时,相应视图的x corrdinate将动画为0。

答案 2 :(得分:0)

Try this

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {

    let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
    let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
    let finalFrameForVC = transitionContext.finalFrameForViewController(toViewController)
    let containerView = transitionContext.containerView()
    let bounds = UIScreen.mainScreen().bounds
    toViewController.view.frame = CGRectOffset(finalFrameForVC, 0, bounds.size.height)
    containerView.addSubview(toViewController.view)

    UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .CurveLinear, animations: {
        fromViewController.view.alpha = 0.5
        toViewController.view.frame = finalFrameForVC
        }, completion: {
            finished in
            transitionContext.completeTransition(true)
            fromViewController.view.alpha = 1.0
    })
}