iOS 動畫效果

來源:互聯網
上載者:User

iOS 動畫效果

最普通動畫:
//開始動畫
[UIView beginAnimations:nil context:nil];
//設定動畫期間
[UIView setAnimationDuration:2];
//動畫的內容
frame.origin.x += 150;
[img setFrame:frame];
//動畫結束
[UIView commitAnimations];

連續動畫:一個接一個地顯示一系列的映像
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@myImage1.png],
[UIImage imageNamed:@myImage2.png],
[UIImage imageNamed:@myImage3.png],
[UIImage imageNamed:@myImage4.gif], nil];

UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages; //animationImages屬性返回一個存放動畫圖片的數組
myAnimatedView.animationDuration = 0.25; //瀏覽整個圖片一次所用的時間
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 動畫重複次數
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];

CATransition Public API動畫:
CATransition *animation = [CATransition animation];
//動畫時間
animation.duration = 0.5f;
//先慢後快
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
//animation.removedOnCompletion = NO;

//各種動畫效果
/*
kCATransitionFade;
kCATransitionMoveIn;
kCATransitionPush;z
kCATransitionReveal;
*/
/*
kCATransitionFromRight;
kCATransitionFromLeft;
kCATransitionFromTop;
kCATransitionFromBottom;
*/
//各種組合
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromRight;

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

CATransition Private API動畫:
animation.type可以設定為以下效果
動畫效果匯總:
/*
suckEffect(三角)

rippleEffect(水波抖動)

pageCurl(上翻頁)

pageUnCurl(下翻頁)

oglFlip(上下翻轉)

cameraIris/cameraIrisHollowOpen/cameraIrisHollowClose (鏡頭快門,這一組動畫是有效果,只是很難看,不建議使用

而以下為則黑名單:

spewEffect: 新版面在螢幕下方中間位置被釋放出來覆蓋舊版面.

- genieEffect: 舊版面在螢幕左下方或右下方被吸走, 顯示出下面的新版面 (阿拉丁燈神?).

- unGenieEffect: 新版面在螢幕左下方或右下方被釋放出來覆蓋舊版面.

- twist: 版面以水平方向像龍捲風式轉出來.

- tubey: 版面垂直附有彈性的轉出來.

- swirl: 舊版面360度旋轉並淡出, 顯示出新版面.

- charminUltra: 舊版面淡出並顯示新版面.

- zoomyIn: 新版面由小放大走到前面, 舊版面放大由前面消失.

- zoomyOut: 新版面螢幕外面縮放出現, 舊版面縮小消失.

- oglApplicationSuspend: 像按home 按鈕的效果.
*/

UIView Animations 動畫:
[UIView beginAnimations:@animationID context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];
//以下四種效果
/*
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//oglFlip, fromLeft
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];//oglFlip, fromRight
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
*/

[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[UIView commitAnimations];
IOS4.0新方法:
方法: +(void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; //多一個動畫結束後可以執行的操作.
//下邊是嵌套使用,先變大再消失的動畫效果.
[UIView animateWithDuration:1.25 animations:^{
CGAffineTransform newTransform = CGAffineTransformMakeScale(1.2, 1.2);
[firstImageView setTransform:newTransform];
[secondImageView setTransform:newTransform];}
completion:^(BOOL finished){
[UIView animateWithDuration:1.2 animations:^{
[firstImageView setAlpha:0];
[secondImageView setAlpha:0];} completion:^(BOOL finished){
[firstImageView removeFromSuperview];
[secondImageView removeFromSuperview]; }];
}];

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.