詳解iPhone開發(fā)中各種動(dòng)畫實(shí)現(xiàn)效果
iPhone開發(fā)中各種動(dòng)畫實(shí)現(xiàn)效果是本文要介紹的內(nèi)容,iphone中存在很多好看的動(dòng)畫效果,用于頁面的切換等。其中某些是apple私有的,據(jù)說私有的無法通過apple的審批。最近工作中剛好用到過其中的某些動(dòng)畫,所以在網(wǎng)上搜了下資料,了解了下這些動(dòng)畫。這里就自己的理解做一下總結(jié),如有錯(cuò)誤或遺漏,盡請諒解。
1、UIView 動(dòng)畫
官方API中,使用UIView可以設(shè)置5個(gè)動(dòng)畫效果,分別為:
- UIViewAnimationTransitionNone 不使用動(dòng)畫
- UIViewAnimationTransitionFlipFromLeft 從左向右旋轉(zhuǎn)翻頁
- UIViewAnimationTransitionFlipFromRight 從右向左旋轉(zhuǎn)翻頁,與UIViewAnimationTransitionFlipFromLeft相反
- UIViewAnimationTransitionCurlUp 卷曲翻頁,從下往上
- UIViewAnimationTransitionCurlDown 卷曲翻頁,從上往下
- 詳細(xì)請參見UIViewAnimationTransition
例子:
- [UIView beginAnimations:@"animationID" context:nil];//開始一個(gè)動(dòng)畫塊,***個(gè)參數(shù)為動(dòng)畫塊標(biāo)識
- [UIView setAnimationDuration:0.5f];//設(shè)置動(dòng)畫的持續(xù)時(shí)間
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- //設(shè)置動(dòng)畫塊中的動(dòng)畫屬性變化的曲線,此方法必須在beginAnimations方法和commitAnimations,默認(rèn)即為UIViewAnimationCurveEaseInOut效果。
- 詳細(xì)請參見UIViewAnimationCurve
- [UIView setAnimationRepeatAutoreverses:NO];//設(shè)置是否自動(dòng)反轉(zhuǎn)當(dāng)前的動(dòng)畫效果
- [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
- //設(shè)置過渡的動(dòng)畫效果,此處***個(gè)參數(shù)可使用上面5種動(dòng)畫效果
- [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//頁面翻轉(zhuǎn)
- [UIView commitAnimations];//提交動(dòng)畫
2、公共動(dòng)畫效果
使用CATransiton可以設(shè)置4種動(dòng)畫效果,分別為:
- NSString * const kCATransitionFade;//漸漸消失
- NSString * const kCATransitionMoveIn;//覆蓋進(jìn)入
- NSString * const kCATransitionPush;//推出
- NSString * const kCATransitionReveal;//與MoveIn相反
例子:
- CATransition *animation = [CATransition animation];
- animation.duration = 0.5f;
- animation.timingFunction = UIViewAnimationCurveEaseInOut;
- animation.type = kCATransitionPush;//設(shè)置上面4種動(dòng)畫效果
- animation.subtype = kCATransitionFromTop;//設(shè)置動(dòng)畫的方向,有四種,
- 分別為kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
- [self.view.layer addAnimation:animation forKey:@"animationID"];
3、私有動(dòng)畫
iphone種還有很多動(dòng)畫是蘋果私有的,例如刪除照片的動(dòng)畫等,
私有動(dòng)畫可以直接在animation.type中傳入動(dòng)畫的字符串即可。動(dòng)畫有以下幾種:
- cube:像立方體一樣翻轉(zhuǎn)
- suckEffect:漸漸縮小,與刪除照片動(dòng)畫一樣
- oglFlip:上下旋轉(zhuǎn),當(dāng)subType為fromLeft或者fromRight時(shí),
- 與UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight一樣
- rippleEffect:水波效果
- pageCurl:與UIViewAnimationTransitionCurlUp一樣
- pageUnCurl:與UIViewAnimationTransitionCurlDown一樣
- cameraIrisHollowOpen:First half of cameraIris.
- cameraIrisHollowClose:Second half of cameraIris
以上所有動(dòng)畫效果的demo請見http://www.cocoachina.com/bbs/read.php?tid-11820.html,在此感謝樓主的分享,給我的學(xué)習(xí)帶來很到的幫助。
UIViewAnimationState描述:http://www.iphonedevwiki.net/index.php/UIViewAnimationState
同時(shí),本人在使用UIView實(shí)現(xiàn)suckEffect縮小的效果過程中遇到一個(gè)問題(不知道如何定位),經(jīng)過搜索終覓得解決方法,分享如下:
- [UIView beginAnimations:@"suck" context:NULL];
- [UIView setAnimationTransition:103 forView:self.view cache:YES];
- [UIView setAnimationDuration:0.5f];
- if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
- {
- [UIView setAnimationPosition:CGPointMake(44, 42)];
- }else {
- [UIView setAnimationPosition:CGPointMake(320 , 42)];
- }
- [UIView commitAnimations];
其中setAnimationPosition方法就是用于設(shè)置縮小點(diǎn)的位置的,此處雖然會報(bào)一個(gè)警告,但是結(jié)果還是正確的。
小結(jié):詳解iPhone開發(fā)中各種動(dòng)畫實(shí)現(xiàn)效果的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!