简体   繁体   English

变换不适用于动画

[英]Transform doesn't work with animation

I'm trying to set up a CALayer to increase in width at the bottom of my viewcontroller by using CATransform3DMakeScale . 我试图通过使用CATransform3DMakeScale在我的视图控制器的底部设置一个CALayer以增加宽度。 I can get the layer to scale just fine, but when I try to apply the transformation through an animation, the layer transforms without any animation. 我可以使图层缩放很好,但是当我尝试通过动画应用转换时,该图层将在没有任何动画的情况下进行转换。

let progressBar1 = CALayer()

override func viewDidAppear() {
    progressBar1.bounds = CGRect(x: 0, y: 0, width: 1, height: 5)
    progressBar1.position = CGPoint(x: 0, y: 600)
    progressBar1.backgroundColor = UIColor.white.cgColor
    view.layer.addSublayer(progressBar1)
    extendBar1()
}

func extendBar1(){
    let transform1 = CATransform3DMakeScale(30, 1, 0)
    let anim = CABasicAnimation(keyPath: "transform")
    anim.isRemovedOnCompletion = false
    anim.fillMode = kCAFillModeForwards
    anim.toValue = NSValue(caTransform3D:transform1)
    anim.duration = 10.00
    progressBar1.add(anim, forKey: "transform")
}

I also tried the following with CATransaction but I get the same result 我也尝试使用CATransaction进行以下操作,但得到的结果相同

func extendBar3(){

    let transform1 = CATransform3DMakeScale(30, 1, 0)

    CATransaction.begin()
    CATransaction.setAnimationDuration(7.0)
    progressBar1.transform = transform1
    CATransaction.commit()
}

The chief remaining problem is this line: 主要的剩余问题是以下行:

    let transform1 = CATransform3DMakeScale(30, 1, 0)

Change the 0 to a 1 . 0更改为1

(The result may still not be the animation you want, precisely, but at least you should see something — as long as (0,600) is not off the screen entirely, of course.) (精确地,结果可能仍然不是您想要的动画,但是至少您应该会看到一些东西,当然,只要(0,600)不在屏幕上完全消失即可。)

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

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