UIViewAnimation動畫與CATransition類動畫


CATransition

 

CATransition is an Objective-C wrapper for creating view transitions. As of 3.1.2, there are 11 types of transitions. 4 of them are SDK-compatible, but are the most boring ones. The following shows all 11 types of transition from picture "A" to "B" at 40%. The subtypes, if any, is "fromLeft".

subtype and filter

Many transitions have are further divided into several discrete subtypes. They often control the movement direction of the animation.

Some transitions accept addition arguments through the filter property, for example, you can set the location of suckEffect using

...
CAFilter* filter = [CAFilter filterWithName:@"suckEffect"];
[filter setValue:[NSValue valueWithCGPoint:CGPointMake(160, 240)] forKey:@"inputPosition"];
transition.filter = filter;
...
Transition Subtypes Accepted parameters
moveIn
push
reveal
fromLeft, fromRight, fromBottom, fromTop -
pageCurl, pageUnCurl fromLeft, fromRight, fromTop, fromBottom float inputColor[];
cube
alignedCube
fromLeft, fromRight, fromTop, fromBottom float inputAmount; (perspective)
flip
alignedFlip
oglFlip
fromLeft, fromRight, fromTop, fromBottom float inputAmount;
cameraIris - CGPoint inputPosition;
rippleEffect - -
rotate 90cw, 90ccw, 180cw, 180ccw -
suckEffect - CGPoint inputPosition;

Availability

The following shows the availability of different CATransitions starting from 2.0

CATransition Availability
fade
moveIn
push
reveal
(Public API) 2.0–
flip
alignedFlip
oglFlip
2.0–
cube
alignedCube
2.0–
pageCurl
pageUnCurl
2.0–
rippleEffect 2.0–
suckEffect 2.0–
cameraIris
cameraIrisHollowOpen
cameraIrisHollowClose
2.0–
rotate 4.0–
spewEffect
genieEffect
unGenieEffect
twist
swirl
charminUltra
reflection
zoomyIn
zoomyOut 
mapCurl
mapUnCurl
oglApplicationSuspend
cameraIrisHollow
2.0–2.2

References

 

UIViewAnimation動畫與Core Animation的CATransition類動畫

1.使用UIView類函數實現:

//UIViewAnimationTransitionFlipFromLeft, 向左轉動
//UIViewAnimationTransitionFlipFromRight, 向右轉動
//UIViewAnimationTransitionCurlUp, 向上翻動
//UIViewAnimationTransitionCurlDown, 向下翻動

 

[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:0.5f]; //動畫時長
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //給視圖添加過渡效果
//在這里寫你的代碼.
[UIView commitAnimations]; //提交動畫

 

2.使用CATransition對象來實現:

CATransition比較強大,一般可以使用CATransition模擬UIView的動畫。

    /* 過渡效果
fade     //交叉淡化過渡(不支持過渡方向)
push     //新視圖把舊視圖推出去
moveIn   //新視圖移到舊視圖上面
reveal   //將舊視圖移開,顯示下面的新視圖
cube     //立方體翻滾效果
oglFlip  //上下左右翻轉效果
suckEffect   //收縮效果,如一塊布被抽走(不支持過渡方向)
rippleEffect //滴水效果(不支持過渡方向)
pageCurl     //向上翻頁效果
pageUnCurl   //向下翻頁效果
cameraIrisHollowOpen  //相機鏡頭打開效果(不支持過渡方向)
cameraIrisHollowClose //相機鏡頭關上效果(不支持過渡方向)
*/

 

/* 過渡方向
fromRight;
fromLeft;
fromTop;
fromBottom;
*/
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.5f; //動畫時長
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.type = @”cube”; //過度效果
animation.subtype = @”formLeft”; //過渡方向
animation.startProgress = 0.0 //動畫開始起點(在整體動畫的百分比)
animation.endProgress = 1.0;  //動畫停止終點(在整體動畫的百分比)
animation.removedOnCompletion = NO;
[self.view.layer addAnimation:animation forKey:@"animation"];

 

轉自:http://www.cnblogs.com/project/archive/2011/09/27/2193556.html

 

實現iPhone漂亮的動畫效果主要有兩種方法

  一種是UIView層面的,

  一種是使用CATransition進行更低層次的控制,

  第一種是UIView,UIView方式可能在低層也是使用CATransition進行了封裝,它只能用於一些簡單的、常用的效果展現,這里寫一個常用的示例代碼,供大家參考。

  Cpp代碼

  [UIView beginAnimations:@"Curl"context:nil];//動畫開始

  [UIView setAnimationDuration:0.75];

  [UIView setAnimationDelegate:self];

  [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];

  [myview removeFromSuperview];

  [UIView commitAnimations];

  第二種方式相對復雜一些,但如果更好的進行控制,還是使用這種方法吧,

  基本使用方法可以看一下如下例子:

  Cpp代碼

  CATransition *animation = [CATransition animation];

  [animation setDuration:1.25f];

  [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

  [animation setType:kCATransitionReveal];

  [animation setSubtype: kCATransitionFromBottom];

  [self.view.layer addAnimation:animation forKey:@"Reveal"];

  這里使用了setType與setSubtype組合,這使用個比較保險,因為他的參數就是官方API里定義的,他們的參數說明可以參考如下:

  [animation setType:@"suckEffect"];

  這里的suckEffect就是效果名稱,可以用的效果主要有:

  Cpp代碼

  pageCurl 向上翻一頁

  pageUnCurl 向下翻一頁

  rippleEffect 滴水效果

  suckEffect 收縮效果,如一塊布被抽走

  cube 立方體效果

  oglFlip 上下翻轉效果

 

 

 

iphone中CABasicAnimation和UIView動畫的區別[轉]

關於UIView動畫:

  1. [UIView beginAnimations :@ "zoom out" context :nil ] ;
  2. [UIView setAnimationDuration : 1. f ] ;
  3. [UIView setAnimationCurve :UIViewAnimationCurveEaseOut ] ;
  4. cover. transform  = CGAffineTransformMakeScale ( 9.25, 7.05 ) ;
  5. cover. center  = CGPointMake ( 430512 ) ;
  6. [UIView commitAnimations ]

UIView動畫是應用在一個view上面的。

關於CABasicAnimation動畫:

  1. -  (CAAnimation  * )animationMove : (CGPoint )rootCenter
  2. {
  3.     CABasicAnimation  *animationMove
  4.      =  [CABasicAnimation animationWithKeyPath :@ "position" ] ;
  5.     animationMove. duration  =  1 ;
  6.     animationMove. autoreverses  = NO ;
  7. //    animationMove.delegate = self;
  8.     animationMove. removedOnCompletion  = NO ;
  9.     animationMove. fillMode  = kCAFillModeForwards ;
  10.     animationMove. fromValue  =  [NSValue valueWithCGPoint :self. oldCoverCenter ] ;
  11.     animationMove. toValue  = [NSValue valueWithCGPoint :rootCenter ] ;
  12.  
  13.      return animationMove ;
  14. }

CABasicAnimation動畫是應用在一個layer上面的。

注:
1,把一個image放在一個view的layer上來放大的時候,如果用UIView來做,圖片不會太多的失真和閃爍的效果,但是用CABasicAnimation來做失真和閃爍現象會很嚴重,效果很不好。
2,做 動畫的疊加效果 很簡單,只要把各自的動畫放在一起就可以了。請看這個效果:一本書邊移動到屏幕中間,邊放大,邊打開封面的效果。

  1. [imageLayer addAnimation : [self animationOpen ] forKey :@ "Open" ] ;
  2. [UIView beginAnimations :@ "zoom out" context :nil ] ;
  3. [UIView setAnimationDuration : 1. f ] ;
  4. [UIView setAnimationCurve :UIViewAnimationCurveEaseOut ] ;
  5. cover. transform  = CGAffineTransformMakeScale ( 5.5, 5.5 ) ;
  6. cover. center  = CGPointMake ( 629384 ) ;
  7. [UIView commitAnimations ] ;
  8.  
  9. -  (CAAnimation  * )animationOpen
  10. {
  11.     CABasicAnimation  *animationOpen
  12.      =  [CABasicAnimation animationWithKeyPath :@ "transform.rotation.y" ] ;
  13.     animationOpen. duration  =  1 ;
  14.     animationOpen. autoreverses  = NO ;
  15.     animationOpen. delegate  = self ;   //然后執行真正地打開書的內容
  16.     animationOpen. removedOnCompletion  = NO ;
  17.     animationOpen. fillMode  = kCAFillModeForwards ;
  18.     animationOpen. fromValue  =  [NSNumber numberWithFloat :-M_PI / 5 ] ;
  19.     animationOpen. toValue  =  [NSNumber numberWithFloat :-M_PI / 1.5 ] ;
  20.  
  21.      return animationOpen ;
  22. }
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM