import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//创建一个按钮,用来点击播放动画
let button:UIButton = UIButton(type:.system)
// button.frame = CGRectMake(10, 20, 100, 30)
button.frame = CGRect(x: 10, y: 20, width: 100, height: 30)
button.setTitle("播放动画", for:UIControlState.normal)
button.addTarget(self,action: #selector(play),for:.touchUpInside)
self.view.addSubview(button);
//添加两个红蓝视图
let redView:UIView = UIView(frame: CGRect(x: 50,y: 50, width: 150, height: 400))
redView.backgroundColor = UIColor.red
self.view.insertSubview(redView, at: 0)
let blueView:UIView = UIView(frame: CGRect(x: 50,y: 50, width: 150, height: 400))
blueView.backgroundColor = UIColor.blue
self.view.insertSubview(blueView, at: 1)
}
func play(){
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(3.0)
UIView.setAnimationTransition(.curlUp, for: self.view, cache: true)
self.view.exchangeSubview(at: 1, withSubviewAt: 0)
UIView.commitAnimations()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
整个屏幕都在动画切换。注意:只有两个页面可以相互切换。