简体   繁体   English

无法在 Swift 中 animateWithDuration 的动画块中放置变换更改

[英]Can't put transform change in animation block of animateWithDuration in Swift

I am trying to change the transform of a layer inside of the animation block of a simple animateWithDuration call in Swift:我正在尝试更改 Swift 中一个简单的animateWithDuration调用的动画块内的层的变换:

UIView.animateWithDuration(0.5, delay: 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseIn , animations: {
            self.zigZag!.layer.mask.transform = CGAffineTransformMakeTranslation(100, 0)
            }, completion: { (finished: Bool) in
        })

However, this always presents me with the following build error:但是,这总是向我显示以下构建错误:

Cannot invoke 'animateWithDuration' with an argument list of type '(Double, animations: () -> Void)'

If I delete the trasnform line or replace it with something else like this:如果我删除 trasnform 行或用其他类似的内容替换它:

self.zigZag!.center = self.view.center

Then the build error goes away and the app builds just fine.然后构建错误消失,应用程序构建得很好。

At this point I'm not sure how I'm supposed to change the transform inside the animation block and get this to build properly.在这一点上,我不确定我应该如何更改动画块内的变换并使其正确构建。

You could omit the Void -> in altogether in your case;在您的情况下,您可以完全省略Void -> in the real culprit that is causing the problem is this line:导致问题的真正罪魁祸首是这一行:

self.zigZag!.layer.mask.transform = CGAffineTransformMakeTranslation(100, 0)

because there is a type mismatch.因为存在类型不匹配。

It should be:它应该是:

Swift 2斯威夫特 2

UIView.animateWithDuration(0.5, delay: 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.CurveEaseIn, animations: {
   self.view!.layer.mask.transform = CATransform3DMakeTranslation(100.0, 0.0, 0.0)
}, completion: nil)

Swift 3, 4, 5斯威夫特 3、4、5

UIView.animate(withDuration: 0.5, delay: 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: UIView.AnimationOptions.curveEaseIn, animations: {
    self.view!.layer.mask.transform = CATransform3DMakeTranslation(100.0, 0.0, 0.0)
}, completion: nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM