如何在 iOS 中对 UIView 变换序列进行动画处理,例如缩放然后旋转?

Wil*_*hen 4 uiviewanimation ios

我想知道如何制作一个首先缩放到尺寸并旋转该尺寸而不是按原始尺寸旋转的 UIView 动画?

我尝试了很多方法,比如在完成一个UIView动画时包装UIView动画,使用UIView animateKeyframes等等。

但是,我无法完美地制作这样的动画,请给我提示或关键字来搜索,谢谢!

Kru*_*nal 5

这应该根据您的要求工作(如何制作一个首先缩放到尺寸并旋转该尺寸而不是按原始尺寸旋转的 UIView 动画?)

@IBOutlet var scaleRotateImage: UIImageView!
func scaleNTransform() -> Void {

    scaleRotateImage.layer.cornerRadius = scaleRotateImage.frame.size.height/2.0
    scaleRotateImage.clipsToBounds = true

    let scaleTransform = CGAffineTransform(scaleX: 3.0, y: 3.0)  // Scale
    let rotateTransform = CGAffineTransform(rotationAngle: CGFloat.pi) // Rotation
    let hybridTransform = scaleTransform.concatenating(rotateTransform) // Both Scale + Rotation

    // Outer block of animation
    UIView.animate(withDuration: 5.0, animations: {
        self.scaleRotateImage.transform = scaleTransform
        self.view.layoutIfNeeded()
    }) { (isCompleted) in

        // Nested block of animation
        UIView.animate(withDuration: 5.0, animations: {
            self.scaleRotateImage.transform = hybridTransform
            self.view.layoutIfNeeded()
        })

    }


}
Run Code Online (Sandbox Code Playgroud)


结果

在此输入图像描述