视图的大小应该是随时可控的。今天我们就来实现对一个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 。欢迎大家訪问。