第一種方法
[UIView beginAnimations:nil context:nil];
// 設置動畫持續時間,單位爲秒
[UIView setAnimationDuration:0.5];
//----------------------
// 需要實現動畫的代碼
// -----------------
[UIView commitAnimations];
只需要將需要動畫效果的代碼放到動畫代碼之間。
關於UIView 動畫的其他屬性,它主要包含在 UIView 的動畫分類中。
第二種簡單動畫實現方法例子:
[UIView animateWithDuration:1.0 animations:^{
// 要實現動畫效果的代碼
CGRect rowRect = row.frame;
rowRect.origin.x = 0;
row.frame = rowRect;
row.alpha = 1;
}];
第三種簡單動畫實現方法例子:
[UIView animateWithDuration:1.0 animations:^{
// 要實現動畫的代碼
CGRect lastRowRect = lastRow.frame;
lastRowRect.origin.x = 320;
lastRow.alpha = 0;
lastRow.frame = lastRowRect;
} completion:^(BOOL finished) {
// 動畫完成後要實現的代碼
[lastRow removeFromSuperview];
BOOL isHaveRow = [self.view.subviews count] != 1 ;
_deleteItemBtn.enabled = isHaveRow ;
}];
這如果是在Android中實現動畫,難度大多了!不知什麼時候谷歌也能再SDK中封裝進更多的動畫效果,讓開發者可以直接調用。