1. UIView類方法動(dòng)畫(huà)
/**
標(biāo)志動(dòng)畫(huà)開(kāi)始,開(kāi)始編輯動(dòng)畫(huà)
@param animationID 動(dòng)畫(huà)的唯一標(biāo)示
@param context 附加參數(shù)
*/
+ (void)beginAnimations:(nullable NSString *)animationID
context:(nullable void *)context;
/**
標(biāo)志動(dòng)畫(huà)結(jié)束冗茸,開(kāi)始執(zhí)行動(dòng)畫(huà)
*/
+ (void)commitAnimations;
/**
設(shè)置動(dòng)畫(huà)時(shí)長(zhǎng)
@param duration duration description
*/
+ (void)setAnimationDuration:(NSTimeInterval)duration;
/**
設(shè)置代理
@param delegate delegate description
*/
+ (void)setAnimationDelegate:(nullable id)delegate;
/**
動(dòng)畫(huà)將要開(kāi)始時(shí)執(zhí)行的方法
@param selector selector description
*/
+ (void)setAnimationWillStartSelector:(nullable SEL)selector;
/**
動(dòng)畫(huà)已經(jīng)結(jié)束時(shí)執(zhí)行的方法
@param selector selector description
*/
+ (void)setAnimationDidStopSelector:(nullable SEL)selector;
/**
設(shè)置動(dòng)畫(huà)執(zhí)行延時(shí)時(shí)間
@param delay delay description
*/
+ (void)setAnimationDelay:(NSTimeInterval)delay;
/**
設(shè)置動(dòng)畫(huà)開(kāi)始的Date
@param startDate startDate description
*/
+ (void)setAnimationStartDate:(NSDate *)startDate;
/**
設(shè)置動(dòng)畫(huà)效果
@param curve curve description
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
UIViewAnimationCurveEaseInOut, // 慢入慢出
UIViewAnimationCurveEaseIn, // 慢入
UIViewAnimationCurveEaseOut, // 慢出
UIViewAnimationCurveLinear, // 線性勻速
};
*/
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;
/**
動(dòng)畫(huà)重復(fù)次數(shù)
@param repeatCount repeatCount description
*/
+ (void)setAnimationRepeatCount:(float)repeatCount;
/**
設(shè)置動(dòng)畫(huà)是否繼續(xù)執(zhí)行反相動(dòng)畫(huà)
@param repeatAutoreverses repeatAutoreverses description
*/
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;
/**
設(shè)置是否從當(dāng)前狀態(tài)開(kāi)始動(dòng)畫(huà)
@param fromCurrentState fromCurrentState description
當(dāng)一個(gè)動(dòng)畫(huà)尚未完成葱蝗,將要進(jìn)行下一個(gè)動(dòng)畫(huà)時(shí):
如果設(shè)置為YES绰播,動(dòng)畫(huà)將從上一個(gè)動(dòng)畫(huà)當(dāng)前的狀態(tài)進(jìn)行下一個(gè)動(dòng)畫(huà)
如果設(shè)置為NO澄耍,那當(dāng)前動(dòng)畫(huà)會(huì)立即結(jié)束,達(dá)到當(dāng)前動(dòng)畫(huà)的最終狀態(tài),再執(zhí)行下一個(gè)動(dòng)畫(huà)
*/
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState;
/**
設(shè)置試圖過(guò)渡效果
@param transition 動(dòng)畫(huà)效果
@param view 添加動(dòng)畫(huà)效果的View
@param cache 是否使用視圖緩存,YES:視圖在開(kāi)始和結(jié)束時(shí)渲染一次;NO:視圖在每一幀都渲染
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
UIViewAnimationTransitionNone, // 不使用動(dòng)畫(huà)
UIViewAnimationTransitionFlipFromLeft, // 從左向右旋轉(zhuǎn)翻頁(yè)
UIViewAnimationTransitionFlipFromRight, // 從右向左旋轉(zhuǎn)翻頁(yè)
UIViewAnimationTransitionCurlUp, // 從下往上卷曲翻頁(yè)
UIViewAnimationTransitionCurlDown, // 從上往下卷曲翻頁(yè)
};
*/
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition
forView:(UIView *)view
cache:(BOOL)cache;
/**
是否禁用動(dòng)畫(huà)效果(對(duì)象的屬性會(huì)被改變便脊,只是沒(méi)有動(dòng)畫(huà)效果)
@param enabled enabled description
*/
+ (void)setAnimationsEnabled:(BOOL)enabled;
2. UIView block動(dòng)畫(huà)
/**
簡(jiǎn)單的動(dòng)畫(huà)方法
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations;
/**
帶有完成回調(diào)的動(dòng)畫(huà)方法
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
/**
帶有延時(shí)和可選擇動(dòng)畫(huà)效果的動(dòng)畫(huà)方法
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param delay 延時(shí)時(shí)長(zhǎng)
@param options 動(dòng)畫(huà)效果(枚舉類型值蚂四,具體效果參考系統(tǒng)系統(tǒng)枚舉)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
/**
spring動(dòng)畫(huà)方法
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param delay 延時(shí)時(shí)長(zhǎng)
@param dampingRatio 震動(dòng)效果,范圍0~1,數(shù)值越小震動(dòng)效果越明顯
@param velocity 初始速度遂赠,數(shù)值越大初始速度越快
@param options 動(dòng)畫(huà)效果(枚舉類型值久妆,具體效果參考系統(tǒng)系統(tǒng)枚舉)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
*/
+ (void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
/**
兩個(gè)視圖切換的轉(zhuǎn)場(chǎng)動(dòng)畫(huà)方法
@param fromView fromView description
@param toView toView description
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param options 動(dòng)畫(huà)效果(枚舉類型值,具體效果參考系統(tǒng)系統(tǒng)枚舉)
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
在該動(dòng)畫(huà)過(guò)程中跷睦,fromView 會(huì)從父視圖中移除筷弦,并講 toView 添加到父視圖中,
注意轉(zhuǎn)場(chǎng)動(dòng)畫(huà)的作用對(duì)象是父視圖抑诸。
*/
+ (void)transitionFromView:(UIView *)fromView
toView:(UIView *)toView
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
completion:(void (^ __nullable)(BOOL finished))completion;
/**
單個(gè)視圖轉(zhuǎn)場(chǎng)效果動(dòng)畫(huà)方法
@param view view description
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param options 動(dòng)畫(huà)效果(枚舉類型值烂琴,具體效果參考系統(tǒng)系統(tǒng)枚舉)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
*/
+ (void)transitionWithView:(UIView *)view
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
animations:(void (^ __nullable)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
/**
關(guān)鍵幀(keyFrame)動(dòng)畫(huà)
@param duration 動(dòng)畫(huà)時(shí)長(zhǎng)
@param delay 延時(shí)時(shí)長(zhǎng)
@param options 動(dòng)畫(huà)效果(枚舉類型值,具體效果參考系統(tǒng)系統(tǒng)枚舉)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
@param completion 動(dòng)畫(huà)完成后需要執(zhí)行的block
*/
+ (void)animateKeyframesWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewKeyframeAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
//其中需要注意的是添加關(guān)鍵幀的方法:
/**
添加關(guān)鍵幀的方法
@param frameStartTime 動(dòng)畫(huà)開(kāi)始的時(shí)間(數(shù)值為占總時(shí)間的比例)
@param frameDuration 動(dòng)畫(huà)持續(xù)時(shí)間(數(shù)值為占總時(shí)間的比例)
@param animations 需要執(zhí)行的動(dòng)畫(huà)block
*/
+ (void)addKeyframeWithRelativeStartTime:(double)frameStartTime
relativeDuration:(double)frameDuration
animations:(void (^)(void))animations;
3. 關(guān)于options參數(shù)
3.1 UIViewAnimationOptions
UIViewAnimationOptionLayoutSubviews //進(jìn)行動(dòng)畫(huà)時(shí)布局子控件
UIViewAnimationOptionAllowUserInteraction //進(jìn)行動(dòng)畫(huà)時(shí)允許用戶交互
UIViewAnimationOptionBeginFromCurrentState //從當(dāng)前狀態(tài)開(kāi)始動(dòng)畫(huà)
UIViewAnimationOptionRepeat //無(wú)限重復(fù)執(zhí)行動(dòng)畫(huà)
UIViewAnimationOptionAutoreverse //執(zhí)行動(dòng)畫(huà)回路
UIViewAnimationOptionOverrideInheritedDuration //忽略嵌套動(dòng)畫(huà)的執(zhí)行時(shí)間設(shè)置
UIViewAnimationOptionOverrideInheritedCurve //忽略嵌套動(dòng)畫(huà)的曲線設(shè)置
UIViewAnimationOptionAllowAnimatedContent //轉(zhuǎn)場(chǎng):進(jìn)行動(dòng)畫(huà)時(shí)重繪視圖
UIViewAnimationOptionShowHideTransitionViews //轉(zhuǎn)場(chǎng):移除(添加和移除圖層的)動(dòng)畫(huà)效果
UIViewAnimationOptionOverrideInheritedOptions //不繼承父動(dòng)畫(huà)設(shè)置
UIViewAnimationOptionCurveEaseInOut //時(shí)間曲線蜕乡,慢進(jìn)慢出(默認(rèn)值)
UIViewAnimationOptionCurveEaseIn //時(shí)間曲線奸绷,慢進(jìn)
UIViewAnimationOptionCurveEaseOut //時(shí)間曲線,慢出
UIViewAnimationOptionCurveLinear //時(shí)間曲線层玲,勻速
UIViewAnimationOptionTransitionNone //轉(zhuǎn)場(chǎng)号醉,不使用動(dòng)畫(huà)
UIViewAnimationOptionTransitionFlipFromLeft //轉(zhuǎn)場(chǎng),從左向右旋轉(zhuǎn)翻頁(yè)
UIViewAnimationOptionTransitionFlipFromRight //轉(zhuǎn)場(chǎng)辛块,從右向左旋轉(zhuǎn)翻頁(yè)
UIViewAnimationOptionTransitionCurlUp //轉(zhuǎn)場(chǎng)畔派,下往上卷曲翻頁(yè)
UIViewAnimationOptionTransitionCurlDown //轉(zhuǎn)場(chǎng),從上往下卷曲翻頁(yè)
UIViewAnimationOptionTransitionCrossDissolve //轉(zhuǎn)場(chǎng)润绵,交叉消失和出現(xiàn)
UIViewAnimationOptionTransitionFlipFromTop //轉(zhuǎn)場(chǎng)线椰,從上向下旋轉(zhuǎn)翻頁(yè)
UIViewAnimationOptionTransitionFlipFromBottom //轉(zhuǎn)場(chǎng),從下向上旋轉(zhuǎn)翻頁(yè)
3.2 UIViewKeyframeAnimationOptions
UIViewKeyframeAnimationOptionLayoutSubviews //進(jìn)行動(dòng)畫(huà)時(shí)布局子控件
UIViewKeyframeAnimationOptionAllowUserInteraction //進(jìn)行動(dòng)畫(huà)時(shí)允許用戶交互
UIViewKeyframeAnimationOptionBeginFromCurrentState //從當(dāng)前狀態(tài)開(kāi)始動(dòng)畫(huà)
UIViewKeyframeAnimationOptionRepeat //無(wú)限重復(fù)執(zhí)行動(dòng)畫(huà)
UIViewKeyframeAnimationOptionAutoreverse //執(zhí)行動(dòng)畫(huà)回路
UIViewKeyframeAnimationOptionOverrideInheritedDuration //忽略嵌套動(dòng)畫(huà)的執(zhí)行時(shí)間設(shè)置
UIViewKeyframeAnimationOptionOverrideInheritedOptions //不繼承父動(dòng)畫(huà)設(shè)置
UIViewKeyframeAnimationOptionCalculationModeLinear //運(yùn)算模式 :連續(xù)
UIViewKeyframeAnimationOptionCalculationModeDiscrete //運(yùn)算模式 :離散
UIViewKeyframeAnimationOptionCalculationModePaced //運(yùn)算模式 :均勻執(zhí)行
UIViewKeyframeAnimationOptionCalculationModeCubic //運(yùn)算模式 :平滑
UIViewKeyframeAnimationOptionCalculationModeCubicPaced //運(yùn)算模式 :平滑均勻