詳解IPhone動(dòng)畫效果類型及實(shí)現(xiàn)方法
詳解IPhone動(dòng)畫效果類型及實(shí)現(xiàn)方法是本文要介紹的內(nèi)容,主要介紹了iphone中動(dòng)畫的實(shí)現(xiàn)方法,不多說,我們一起來看內(nèi)容。
實(shí)現(xiàn)iphone漂亮的動(dòng)畫效果主要有兩種方法,一種是UIView層面的,一種是使用CATransition進(jìn)行更低層次的控制.
1、UIView
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDuration:1.0]; //動(dòng)畫持續(xù)的時(shí)間
- //這里添加你對(duì)UIView所做改變的代碼
- //[UIView setAnimationDidStopSelector:@selector(animationFinished:)]; //動(dòng)畫停止后,執(zhí)行某個(gè)方法
- [UIView commitAnimations];
2、UIView(使用Cocoa Touch)
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
- // Cocoa Touch
- [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:myView cache:YES];
- [UIView setAnimationDelegate:self];
- //[UIView setAnimationDidStopSelector:@selector(animationFinished:)]; //動(dòng)畫停止后,執(zhí)行某個(gè)方法
- [UIView commitAnimations];
- 動(dòng)畫方式(UIViewAnimationTransition):
- UIViewAnimationTransitionFlipFromLeft //從左向右翻轉(zhuǎn)
- UIViewAnimationTransitionFlipFromRight //從右向左翻轉(zhuǎn)
- UIViewAnimationTransitionCurlUp //從下向上翻頁
- UIViewAnimationTransitionCurlDown //從上向下翻頁
3、CATransition
- CATransition *animation = [CATransition animation];
- animation.delegate = self;
- animation.duration = 1.0f; //動(dòng)畫執(zhí)行時(shí)間
- animation.timingFunction = UIViewAnimationCurveEaseInOut;
- animation.type = kCATransitionFade;
- animation.subtype = kCATransitionFromRight;
- // 這里添加你對(duì)UIView所做改變的代碼
- [[myView layer] addAnimation:animation forKey:@"animation"];
setType:有四種類型:
- kCATransitionFade //交叉淡化過渡
- kCATransitionMoveIn //移動(dòng)覆蓋原圖
- kCATransitionPush //新視圖將舊視圖推出去
- kCATransitionReveal //底部顯出來
setSubtype:有四種類型:
- kCATransitionFromRight;
- kCATransitionFromLeft(默認(rèn)值)
- kCATransitionFromTop;
- kCATransitionFromBottom
- 注:kCATransitionFade 不支持Subtype
4、CATransition(只使用setType,參數(shù)是NSString)
- CATransition *animation = [CATransition animation];
- animation.delegate = self;
- animation.duration = 1.0f; //動(dòng)畫執(zhí)行時(shí)間
- animation.timingFunction = UIViewAnimationCurveEaseInOut;
- animation.type = @"suckEffect";// 這里添加你對(duì)UIView所做改變的代碼
- [[myView layer] addAnimation:animation forKey:@"animation"];
可以用的效果主要有:
- pageCurl //向上翻一頁
- pageUnCurl //向下翻一頁
- rippleEffect //滴水效果
- suckEffect //收縮效果,如一塊布被抽走
- cube //立方體效果
- oglFlip //上下翻轉(zhuǎn)效果
小結(jié):詳解IPhone動(dòng)畫效果類型及實(shí)現(xiàn)方法的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!