iOS 簡單動畫效果

來源:互聯網
上載者:User
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]

通常這個View會是放大到全屏,或者半屏大小,然後再點擊後,自動消失。所以這個View會被自義成一個新的View,然後在接收點擊事件後,調用[self removeFromParentView];的方法


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];

}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.