iOS開發(fā)中的小技巧2:UIView緩沖出現(xiàn)

開發(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為動畫

下面是可以設(shè)置動畫效果的屬性:

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í)行前等待的時間

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容