1,首先,在iOS中,動畫有2種,一種是對 UIView 作動畫處理,另外一種是對 CALayer作動畫。html
這裏咱們先要搞清楚 UIView 與 CALayer 之間的關係,UIView 是界面的基礎元素,是根據CoreAnimation 來繪製的,UIView 有個 layer 屬性,每一個uiview 都有個layer 層,也能夠在layer 上添加其餘 layer 層。iview
下面這段是對 uiview 的動畫:動畫
CGContextRef context = UIGraphicsGetCurrentContext(); // 獲取圖形上下文 [UIView beginAnimations:nil context:context]; // 開始動畫 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //開始和結束時動畫效果比較慢,枚舉四種過渡效果 [UIView setAnimationDuration:2.0]; //動畫持續時間 [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(viewFadeOut)]; // 動畫結束後執行 [imageview setAlpha:1.0f]; [UIView commitAnimations]; // 動畫完成
setAnimationWillStartSelectorui
動畫即將開始執行
下面是做用於 layer 層的動畫:spa
CATransition *animation = [CATransition animation];3d
[animation setDuration:2.0f];code
[animation setTimingFunction:[CAMediaTimingFunctionhtm
functionWithName:kCAMediaTimingFunctionEaseIn]];animation
[animation setType:kCATransitionReveal];it
[animation setSubtype: kCATransitionFromTop];
[self.view.layer addAnimation:animation forKey:@"animation"];
setDuration:和UIView中的動畫效果同樣,持續時間.
setTimingFunction:是動畫的種類,和UIView同樣,好比勻速動畫,快速開始結束等.
setType:是指定動畫的類型,他有: