Swift transform rotate Lottie 动画不工作
Swift transform rotate Lottie animatino not working
我有一个简单的LottieAnimationView
,我想将它旋转90度,但是.transform
没有任何影响。它正在显示,但未应用转换。
我是这样设置的:
self.view.addSubview(arrowAnimation)
arrowAnimation.translatesAutoresizingMaskIntoConstraints = false
arrowAnimation.heightAnchor.constraint(equalToConstant: screenSize.width/3).isActive = true
arrowAnimation.bottomAnchor.constraint(equalTo: introLabel.topAnchor, constant: -20).isActive = true
arrowAnimation.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
arrowAnimation.contentMode = .scaleAspectFit
arrowAnimation.transform.rotated(by: .pi / 2)
arrowAnimation.animationSpeed = 1.5
arrowAnimation.loopMode = .playOnce
知道为什么 transform
在这里不起作用吗?
以下将起作用:
arrowAnimation.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
至于原因:
.transform.rotated(by: .pi/2) returns 一个转换,但不应用它,所以你需要改为:
arrowAnimation.transform = arrowAnimation.transform.rotated(by: .pi/2)
我有一个简单的LottieAnimationView
,我想将它旋转90度,但是.transform
没有任何影响。它正在显示,但未应用转换。
我是这样设置的:
self.view.addSubview(arrowAnimation)
arrowAnimation.translatesAutoresizingMaskIntoConstraints = false
arrowAnimation.heightAnchor.constraint(equalToConstant: screenSize.width/3).isActive = true
arrowAnimation.bottomAnchor.constraint(equalTo: introLabel.topAnchor, constant: -20).isActive = true
arrowAnimation.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
arrowAnimation.contentMode = .scaleAspectFit
arrowAnimation.transform.rotated(by: .pi / 2)
arrowAnimation.animationSpeed = 1.5
arrowAnimation.loopMode = .playOnce
知道为什么 transform
在这里不起作用吗?
以下将起作用:
arrowAnimation.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
至于原因:
.transform.rotated(by: .pi/2) returns 一个转换,但不应用它,所以你需要改为:
arrowAnimation.transform = arrowAnimation.transform.rotated(by: .pi/2)