zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

iOS项目开发实战——制作视图的缩放动画

ios动画项目开发 实战 视图 制作 缩放
2023-09-14 09:09:00 时间

     视图的大小应该是随时可控的。今天我们就来实现对一个View的缩放动画。该动画的实现与位移动画,透明度动画稍有不同。

详细实现例如以下:

import UIKit

class ScaleViewController: UIViewController {

    
    
    @IBOutlet weak var greenSquare: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        func anim(){
        
            self.greenSquare.transform = CGAffineTransformMakeScale(0.5, 0.5)//缩小为原来的0.5倍。
        }
        
        
        UIView.animateWithDuration(1, animations: anim)
        
        
        
    }

}

(3)执行程序。发现View能够变为原来X。Y轴上的0.5倍。


github主页:https://github.com/chenyufeng1991  。欢迎大家訪问。