UIView变换动画未被调用

时间:2017-05-05 02:27:01

标签: ios swift uiview core-animation uiviewanimation

目前有一种观点,我试图同时翻译(移动),旋转和缩放视图。由于这么奇怪的原因,当我把比例放在底部时,它只是缩放它。但是,当我更改顺序并首先放置缩放时,它会旋转并正确转换视图,但在更改回原始大小之前,视图的比例会短暂更改为正确的比例。我需要它保持它的缩放形式。这是代码:

class ViewController: UIViewController {


 let newView = UIView(frame: CGRect(x: 10, y: 10, width: 100, height: 100))


  override func viewDidLoad() {
    super.viewDidLoad()


    self.view.addSubview(newView)


    UIView.animate(withDuration: 1.0, animations: {


      self.newView.transform = CGAffineTransform(translationX: 50, y: 70)//translation
      self.newView.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)//rotation
      self.newView.transform = CGAffineTransform(scaleX: 1, y: 0.5)//scale
    })
  }
}

1 个答案:

答案 0 :(得分:1)

首先尝试合并变换,然后一次应用它们:

    let translate = CGAffineTransform(translationX: 50, y: 70)

    UIView.animate(withDuration: 1.0, animations: {
        self.view.transform =  translate.rotated(by: -CGFloat.pi / 2).scaledBy(x: 1, y: 0.5)
    })