開發(fā)中有時需要動態(tài)加載一些圖像噪奄,突然出現(xiàn)會有突兀感,所以需要有一個緩沖;此時可以用UIView aanimateWithDuration的方法實現(xiàn)動畫效果颜及。
@interface UIView(UIViewAnimationWithBlocks)
+ (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);
+ (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
其中 :duration為動畫時間? animations為動畫
下面是可以設置動畫效果的屬性:
frame掖肋、bounds仆葡、center、transform、alpha沿盅、backgroundColor把篓、contentStretch
例如frame:(兩秒出現(xiàn)完全)
[UIView animateWithDuration:0.20 animations:^{
button.frame = CGRectMake(51, 50, 80, 2);
}];
例如淡出、出現(xiàn)
[UIView animateWithDuration:1.0 animations:^{
firstView.alpha = 0.0;
secondView.alpha = 1.0;
}];
completion為動畫執(zhí)行完畢以后執(zhí)行的代碼塊
options為動畫執(zhí)行的選項腰涧。
delay為動畫開始執(zhí)行前等待的時間