最近在寫(xiě)一個(gè)動(dòng)畫(huà)效果的時(shí)候,發(fā)現(xiàn)有個(gè)常用的參數(shù):動(dòng)畫(huà)的速度控制參數(shù),之前對(duì)它沒(méi)有什么深入理解.今天突然來(lái)了興趣,就來(lái)詳細(xì)研究下它.
一.UIViewAnimationOptions是什么?
它是控制動(dòng)畫(huà)效果的一個(gè)選項(xiàng),這里我重點(diǎn)研究的動(dòng)畫(huà)速度控制相關(guān)的內(nèi)容免糕。
首先,貼一段常用的UIView動(dòng)畫(huà)代碼:
[UIView animateWithDuration:1 animations:^{
// 動(dòng)畫(huà)代碼
} completion:^(BOOL finished) {
}];
此時(shí),是不用傳入options參數(shù)的, 這是完整的UIView動(dòng)畫(huà)的方法:
[UIView animateWithDuration:1 delay:0 options:options animations:^{
// 動(dòng)畫(huà)代碼
} completion:^(BOOL finished) {
}];
這里的options就是控制動(dòng)畫(huà)效果的枚舉類(lèi)型 UIViewAnimationOptions
它有四個(gè)枚舉值是跟速度控制相關(guān)的: UIViewAnimationOptionCurveEaseInOut,UIViewAnimationOptionCurveEaseIn,UIViewAnimationOptionCurveEaseOut,和UIViewAnimationOptionCurveLinear, 蘋(píng)果文檔對(duì)它解釋如下:
UIViewAnimationOptionCurveEaseInOut
Specify an ease-in ease-out curve, which causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing.
UIViewAnimationOptionCurveEaseIn
An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.
UIViewAnimationOptionCurveEaseOut
An ease-out curve causes the animation to begin quickly, and then slow as it completes.
UIViewAnimationOptionCurveLinear
A linear animation curve causes an animation to occur evenly over its duration.
但是僅僅通過(guò)文字描述,顯然是不夠直觀,干脆做個(gè)動(dòng)畫(huà),來(lái)個(gè)直觀感受:
二.動(dòng)畫(huà)效果演示:
我用OC寫(xiě)了個(gè)demo赢乓,上面是一個(gè)UIView動(dòng)畫(huà), 下面是展示動(dòng)畫(huà)運(yùn)動(dòng)距離的函數(shù)曲線:
UIViewAnimationOptionCurveEaseInOut
UIViewAnimationOptionCurveEaseIn
UIViewAnimationOptionCurveEaseOut
UIViewAnimationOptionCurveLinear
三.代碼
對(duì)這個(gè)小demo感興趣的話石窑,稍后會(huì)貼出github地址牌芋。