1. 程式人生 > >iPhone開發--漸隱漸顯動畫效果

iPhone開發--漸隱漸顯動畫效果

1、最簡單,最實用,最常用的[移動動畫]

//移動一個view

---------------------------------------------------------------------------------------------------------------------------------

+(void)MoveView:(UIView *)view To:(CGRect)frame During:(float)time{

// 動畫開始

[UIView beginAnimations:nil context:nil];

// 動畫時間曲線 EaseInOut效果

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// 動畫時間

[UIView setAnimationDuration:time];

view.frame = frame;

// 動畫結束(或者用提交也不錯)

[UIView commitAnimations];

}

---------------------------------------------------------------------------------------------------------------------------------

適用範圍:

常常出現在ipad專案中,當用戶點選一個圖片,或者一條資訊,你將彈出一個詳細頁面[detailview],將起始frame初始化為 cgrectmake(self.view.frame.size.width/2,self.view.size.height/2, 0, 0),結束位置[frame] ,常用的動畫間隔時間0.4f-0.6f。

[AnimtionTool MoveView:detailview To:frame During:0.5f];

效果,頁面中間將從小到大顯示一個view[detailview]


2、漸漸顯示一個view,需要在呼叫此方法的類中重寫此方法

---------------------------------------------------------------------------------------------------------------------------------

/*

- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

      if ([animationID isEqualToString: SHOW_VIEW]) {

         //do something

      }  else if ([animationID isEqualToString:HIDDEN_VIEW]) {

         //do something

      }

}

*/

+(void)ShowView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate;{

[UIView beginAnimations:SHOW_VIEW context:nil];

[UIView setAnimationDuration:time];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){

[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];

[UIView setAnimationDelegate:delegate];

}

view.hidden = NO;

view.layer.opacity = 1.0;

view.frame = frame;

[UIView commitAnimations];

}

---------------------------------------------------------------------------------------------------------------------------------

3、漸漸隱藏一個view

---------------------------------------------------------------------------------------------------------------------------------

+(void)HiddenView:(UIView *)view To:(CGRect)frame During:(float)time delegate:(id)delegate{

[UIView beginAnimations:HIDDEN_VIEW context:nil];

[UIView setAnimationDuration:time];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

if(delegate !=nil &&[delegate respondsToSelector:@selector(onAnimationComplete:finished:context:)]){

[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];

[UIView setAnimationDelegate:delegate];

}

view.frame = frame;

view.layer.opacity = 0.0;

[UIView commitAnimations];

}

---------------------------------------------------------------------------------------------------------------------------------

轉自:http://blog.csdn.net/andypan1314/article/details/6433358