UIView動畫一般使用
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL
這兩個方法,在動畫過程中手勢交互默認(rèn)是關(guān)閉的武鲁。
可以使用
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
設(shè)置options為UIViewAnimationOptionAllowUserInteraction來打開交互爽雄。
UIViewAnimationOptions是一個動畫效果的枚舉值,它可以影響動畫的執(zhí)行效果沐鼠。
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
UIViewAnimationOptionLayoutSubviews = 1 << 0, // 設(shè)置子視圖隨父視圖展示動畫
UIViewAnimationOptionAllowUserInteraction = 1 << 1, // 允許在動畫執(zhí)行時用戶與其進(jìn)行交互
UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // 允許在動畫執(zhí)行時執(zhí)行新的動畫
UIViewAnimationOptionRepeat = 1 << 3, // 設(shè)置動畫循環(huán)執(zhí)行
UIViewAnimationOptionAutoreverse = 1 << 4, // 設(shè)置動畫反向執(zhí)行挚瘟,需要設(shè)置動畫循環(huán)
UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // 強(qiáng)制動畫使用內(nèi)層動畫的時間值
UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // 強(qiáng)制動畫使用內(nèi)層動畫曲線值
UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // 設(shè)置動畫視圖實(shí)時刷新
UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // 設(shè)置視圖切換時隱藏,而不是移除
UIViewAnimationOptionOverrideInheritedOptions = 1 << 9, // 這部分屬性設(shè)置動畫播放的線性效果
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // 淡入淡出 首末減速
UIViewAnimationOptionCurveEaseIn = 1 << 16, // 淡入 初始減速
UIViewAnimationOptionCurveEaseOut = 2 << 16, // 淡出 末尾減速
UIViewAnimationOptionCurveLinear = 3 << 16, // 線性 勻速執(zhí)行
UIViewAnimationOptionTransitionNone = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20, // 從左邊切入
UIViewAnimationOptionTransitionFlipFromRight = 2 << 20, // 從右邊切入
UIViewAnimationOptionTransitionCurlUp = 3 << 20, // /從上面立體進(jìn)入
UIViewAnimationOptionTransitionCurlDown = 4 << 20, // /從下面立體進(jìn)入
UIViewAnimationOptionTransitionCrossDissolve = 5 << 20, // 溶解效果
UIViewAnimationOptionTransitionFlipFromTop = 6 << 20, // 從上面切入
UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20, // 從下面切入
} NS_ENUM_AVAILABLE_IOS(4_0);
原諒我的渣英語饲梭,枚舉值翻譯摘自iOS動畫開發(fā)之一——UIViewAnimation動畫的使用
屬性可以使用|進(jìn)行多項合并乘盖。
[UIView animateWithDuration:1.8f delay:0.f options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAllowUserInteraction animations:^{
…………
} completion:^(BOOL finished) {
…………
}];