【问题标题】:Swift transform rotate Lottie animatino not working快速变换旋转洛蒂动画不起作用
【发布时间】:2021-01-26 03:45:19
【问题描述】:

我有一个简单的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 在这里不起作用吗?

【问题讨论】:

    标签: ios swift uiview transform lottie


    【解决方案1】:

    以下将起作用:

    arrowAnimation.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
    

    至于为什么:

    .transform.rotated(by: .pi/2) 返回一个转换,但不应用它,所以你需要改为:

    arrowAnimation.transform = arrowAnimation.transform.rotated(by: .pi/2) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 2016-02-05
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多