網(wǎng)址:http://www.cnblogs.com/chivas/archive/2012/06/08/2541807.html
ios各種動(dòng)畫效果
最普通動(dòng)畫:
//開始動(dòng)畫
[UIView beginAnimations:nil context:nil];
//設(shè)定動(dòng)畫持續(xù)時(shí)間
[UIView setAnimationDuration:2];
//動(dòng)畫的內(nèi)容
frame.origin.x += 150;
[img setFrame:frame];
//動(dòng)畫結(jié)束
[UIView commitAnimations];
連續(xù)動(dòng)畫:一個(gè)接一個(gè)地顯示一系列的圖像
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屬性返回一個(gè)存放動(dòng)畫圖片的數(shù)組
myAnimatedView.animationDuration = 0.25; //瀏覽整個(gè)圖片一次所用的時(shí)間
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 動(dòng)畫重復(fù)次數(shù)
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];
CATransition Public API動(dòng)畫:
CATransition *animation = [CATransition animation];
//動(dòng)畫時(shí)間
animation.duration = 0.5f;
//先慢后快
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
//animation.removedOnCompletion = NO;
//各種動(dòng)畫效果
/*
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動(dòng)畫:
animation.type可以設(shè)定為以下效果
動(dòng)畫效果匯總:
/*
suckEffect(三角)
rippleEffect(水波抖動(dòng))
pageCurl(上翻頁(yè))
pageUnCurl(下翻頁(yè))
oglFlip(上下翻轉(zhuǎn))
cameraIris/cameraIrisHollowOpen/cameraIrisHollowClose? (鏡頭快門担巩,這一組動(dòng)畫是有效果膊毁,只是很難看每币,不建議使用
而以下為則黑名單:
spewEffect: 新版面在屏幕下方中間位置被釋放出來覆蓋舊版面.
- genieEffect: 舊版面在屏幕左下方或右下方被吸走, 顯示出下面的新版面 (阿拉丁燈神?).
- unGenieEffect: 新版面在屏幕左下方或右下方被釋放出來覆蓋舊版面.
- twist: 版面以水平方向像龍卷風(fēng)式轉(zhuǎn)出來.
- tubey: 版面垂直附有彈性的轉(zhuǎn)出來.
- swirl: 舊版面360度旋轉(zhuǎn)并淡出, 顯示出新版面.
- charminUltra: 舊版面淡出并顯示新版面.
- zoomyIn: 新版面由小放大走到前面, 舊版面放大由前面消失.
- zoomyOut: 新版面屏幕外面縮放出現(xiàn), 舊版面縮小消失.
- oglApplicationSuspend: 像按"home" 按鈕的效果.
*/
UIView Animations 動(dòng)畫:
[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; //多一個(gè)動(dòng)畫結(jié)束后可以執(zhí)行的操作.
//下邊是嵌套使用,先變大再消失的動(dòng)畫效果.
[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]; }];
}];