1.非代碼塊的動畫操作掸犬,都是對父視圖進行操作的
2.另外3種可以加延遲的動畫,原理類似(后面兩個參數(shù)是閉包,類似于于OC中的block代碼塊)
1:(UIViewAnimationOptions: 動畫過渡效果)
// UIView.animateWithDuration(<#T##duration: NSTimeInterval##NSTimeInterval#>, delay: <#T##NSTimeInterval#>, options: <#T##UIViewAnimationOptions#>, animations: <#T##() -> Void#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
2:Spring Animation :
(1)usingSpringWithDamping:它的范圍為 0.0f 到 1.0f 通砍,數(shù)值越小「彈簧」的振動效果越明顯。
(2)initialSpringVelocity:初始的速度烤蜕,數(shù)值越大一開始移動越快封孙。值得注意的是,初始速度取值較高而時間較短時讽营,也會出現(xiàn)反彈情況虎忌。
usingSpringWithDamping: 類似彈簧振動效果 0~1
initialSpringVelocity: 初始速度
UIViewAnimationOptions: 動畫過渡效果
UIView.animateWithDuration(<#T##duration: NSTimeInterval##NSTimeInterval#>, delay: <#T##NSTimeInterval#>, usingSpringWithDamping: <#T##CGFloat#>, initialSpringVelocity: <#T##CGFloat#>, options: <#T##UIViewAnimationOptions#>, animations: <#T##() -> Void#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
3:關(guān)鍵幀動畫 : (參數(shù)解釋如下:)
duration 動畫時長
delay 動畫延遲
options 動畫效果選項
animations 動畫執(zhí)行代碼
completion 動畫結(jié)束執(zhí)行代碼
// UIView.animateKeyframesWithDuration(<#T##duration: NSTimeInterval##NSTimeInterval#>, delay: <#T##NSTimeInterval#>, options: <#T##UIViewKeyframeAnimationOptions#>, animations: <#T##() -> Void#>, completion: <#T##((Bool) -> Void)?##((Bool) -> Void)?##(Bool) -> Void#>)
func createAnimation(){
// 創(chuàng)建一個view視圖
let view = UIView.init(frame: CGRectMake(100, 100, 100, 100))
view.backgroundColor = UIColor.yellowColor()
self.view.addSubview(view)
//非代碼塊的動畫操作,都是對父視圖進行操作的
//開啟動畫
UIView.beginAnimations(nil, context: nil)
//設(shè)置動畫時間(默認(rèn)單位為秒 s)
UIView.setAnimationDuration(1)
//設(shè)置動畫啟動延遲時間
// UIView.setAnimationDelay(2)
//設(shè)置UIView的動畫代理
UIView.setAnimationDelegate(self)
//動畫結(jié)束后執(zhí)行的操作
UIView.setAnimationDidStopSelector(#selector(self.stop))
//可以改變其子視圖的大小斑匪、位置呐籽、顏色、透明度等等
//動畫的最終結(jié)果
view.frame = self.view.frame
view.backgroundColor = UIColor.redColor()
//結(jié)束動畫
UIView.commitAnimations()
}
func stop(){
//創(chuàng)建提示框
let alertView2 = UIAlertController.init(title: "結(jié)束", message: "是否重來", preferredStyle: UIAlertControllerStyle.Alert)
//讓提示框在視圖中顯示出來
self.presentViewController(alertView2, animated: true, completion: nil)
}