本文及其之后的講解是依據Raywenderich 的 Animation Tutorial這一本書和蘋果官方文檔總結而來,特此聲明!
- 參數解釋
*如解釋有誤,請指出,謝謝*
1 duration: 動畫執行時間
2 delay:動畫延遲執行時間
3 options:
基本參數:
.LayoutSubviews:在AutoLayout下,如果修改AutoLayout,那么子視圖也會跟著一起變化
.AllowUserInteraction:在動畫時,允許用戶交互
.BeginFromCurrentState:允許在動畫執行時執行新的動畫
.Repeat:永遠重復的運行
.Autoreverse:動畫執行結束后按照相反的行為繼續執行,該屬性只能和.Repeat屬性組合使用
.OverrideInheritedDuration:強制動畫使用內層動畫的時間值
.OverrideInheritedCurve:強制動畫使用內層動畫曲線值
線性參數:
.CurveLinear:動畫做線性運動
.CurveEaseIn:動畫緩慢開始,然后逐漸加速
.CurveEaseOut:動畫迅速開始,在結束時減速
.CurveEaseInOut:動畫慢慢開始,然后加速,在結束之前減速
轉場參數:
.TransitionNone:沒有轉場動畫
.TransitionFlipFromTop :從頂部圍繞水平軸做翻轉動畫
.TransitionFlipFromBottom:從底部圍繞水平軸做翻轉動畫
.TransitionFlipFromLeft :從左側圍繞垂直軸做翻轉動畫
.TransitionFlipFromRight:從右側圍繞垂直軸做翻轉動畫
.TransitionCurlUp:從下往上做翻頁動畫
.TransitionCurlDown :從上往下做翻頁動畫
.TransitionCrossDissolve:視圖溶解消失顯示新視圖動畫
4 usingSpringWithDamping:彈簧阻力,取值范圍為0.0-1.0,數值越小“彈簧”振動效果越明顯。
5 initialSpringVelocity:動畫初始的速度(pt/s),數值越大初始速度越快。但要注意的是,初始速度取值較高而時間較短時,也會出現反彈情況。
- 普通動畫
- animateWithDuration:delay:options:animations:completion:
class func animateWithDuration(_ duration: NSTimeInterval,
delay delay: NSTimeInterval,
options options: UIViewAnimationOptions,
animations animations: () -> Void,
completion completion: ((Bool) -> Void)?)
Animate changes to one or more views using the specified duration, delay, options, and completion handler.
對一個或者多個視圖按照相應參數做固定動畫(翻譯純屬個人見解,有錯請指出)
- animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:
class func animateWithDuration(_ duration: NSTimeInterval,
delay delay: NSTimeInterval,
usingSpringWithDamping dampingRatio: CGFloat,
initialSpringVelocity velocity: CGFloat,
options options: UIViewAnimationOptions,
animations animations: () -> Void,
completion completion: ((Bool) -> Void)?)
Performs a view animation using a timing curve corresponding to the motion of a physical spring.
對一個視圖按照相應參數做彈性動畫(類似于彈簧,翻譯純屬個人見解,有錯請指出)
圖片借鑒Renfei Song's Blog,只為更清楚的展示調用兩個API的不同效果
Spring Animation 和普通的動畫的運動曲線的對比:
Spring Animation, Ease-Out Animation 和 Linear Animation 的動畫效果:
- 轉場動畫
- transitionWithView:duration:options:animations:completion:
class func transitionWithView(_ view: UIView,
duration duration: NSTimeInterval,
options options: UIViewAnimationOptions,
animations animations: (() -> Void)?,
completion completion: ((Bool) -> Void)?)
Creates a transition animation for the specified container view.
為指定的視圖構建一個過渡動畫(翻譯純屬個人見解,有錯請指出)
- transitionFromView:toView:duration:options:completion:
class func transitionFromView(_ fromView: UIView,
toView toView: UIView,
duration duration: NSTimeInterval,
options options: UIViewAnimationOptions,
completion completion: ((Bool) -> Void)?)
Creates a transition animation between the specified views using the given parameters.
在兩個給定視圖之間構建過渡動畫(翻譯純屬個人見解,有錯請指出)