簡單動畫 (二) 之Core Animation

Core Animation 是iOS中一個比較重要的框架,許多炫酷動畫和效果都可以用Core Animation 來實現(xiàn),下面我們先簡單的認(rèn)識了解下Core Animation.

認(rèn)識 Core Animation

在QuartzCore這個framwork 中提供了一下這些類


在Core Animation中提供了一個基本類 CAAnimation 通過查看文檔我們可以看到一些方法和屬性

@interface CAAnimation : NSObject

{@private? void *_attr;?

?uint32_t _flags;

}

/* Creates a new animation object. */

+ (instancetype)animation;

/* Animations implement the same property model as defined by CALayer. * See CALayer.h for more details. */

+ (nullable id)defaultValueForKey:(NSString *)key;

- (BOOL)shouldArchiveValueForKey:(NSString *)key;

/* A timing function defining the pacing of the animation. Defaults to * nil indicating linear pacing. */

@property(nullable, strong) CAMediaTimingFunction *timingFunction;

/* The delegate of the animation. This object is retained for the * lifetime of the animation object. Defaults to nil. See below for the * supported delegate methods. */

@property(nullable, strong) id delegate;

/* When true, the animation is removed from the render tree once its

* active duration has passed. Defaults to YES. */

@property(getter=isRemovedOnCompletion) BOOL removedOnCompletion;

@end

這個類是最基本的抽象類 ,主要提供了創(chuàng)建類方法 ,動畫執(zhí)行方法 以及是否在執(zhí)行完成后移除等.

我們常用到的動畫主要涉及到以下幾個類

CABasicAnimation宵凌、CAKeyframeAnimation、CATransition里覆、CAAnimationGroup 菲饼、CASpringAnimation

在文檔往下繼續(xù)查看 我們能看到更多的類,多層次繼承關(guān)系

CAPropertyAnimation : CAAnimation

CABasicAnimation : CAPropertyAnimation

CAKeyframeAnimation : CAPropertyAnimation

CASpringAnimation : CABasicAnimation

CAAnimationGroup : CAAnimation

CATransition : CAAnimation


1 ? ?CABasicAnimation 的使用

? 改變透明度

- (IBAction)baseClick:(id)sender {

CABasicAnimation* animation=[CABasicAnimation animationWithKeyPath:@"opacity"];

animation.fromValue=[NSNumber numberWithFloat:1.0];

animation.toValue=[NSNumber numberWithFloat:0.00];

//默認(rèn)是NO? YES 表示重復(fù)循環(huán)

animation.autoreverses=YES;

animation.duration=1;

animation.repeatCount=10;//重復(fù)次數(shù)

animation.removedOnCompletion=NO;//執(zhí)行完成后是否移除

animation.fillMode=kCAFillModeForwards;//效果可選擇

/** Timing function names.

CA_EXTERN NSString * const kCAMediaTimingFunctionLinear

CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

CA_EXTERN NSString * const kCAMediaTimingFunctionEaseIn

CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

CA_EXTERN NSString * const kCAMediaTimingFunctionEaseOut

CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

CA_EXTERN NSString * const kCAMediaTimingFunctionEaseInEaseOut

CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);

CA_EXTERN NSString * const kCAMediaTimingFunctionDefault

CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);

NS_ASSUME_NONNULL_END

**/

animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

[self.baseBtn.layer addAnimation:animation forKey:@"alpha"];

}

效果




2 ? CATransition 的轉(zhuǎn)場動畫

之前我們就知道CATransition繼承于CAAniamtion ,CATransition用于做轉(zhuǎn)場動畫恢共,能夠為層提供移出屏幕和移入屏幕的動畫效果砂心。


@interface CATransition : CAAnimation

@property(copy) NSString *type;? //動畫過渡類型

@property(nullable, copy) NSString *subtype; //動畫過渡方向

@property float startProgress;

@property float endProgress;

@property(nullable, strong) id filter;

@end

type的值解讀對應(yīng)常量

fade ? ? ? 淡入淡出 ? ?kCATransitionFade

push ? ? ? ? 推擠 ? ? ? ? kCATransitionPush

reveal ? ? ? 揭開 ? ? ? ? kCATransitionReveal

moveIn ? ?覆蓋 ? ? ? ? ?kCATransitionMoveIn

cube ? ? ? 立方體 ? ? ? ? ? 私有API

suckEffect 吮吸 ? ? ? ? ? 私有API

oglFlip ? ? ? ? 翻轉(zhuǎn) ? ? ? ? ? 私有API

rippleEffect ?波紋 ? ? ? ? 私有API

pageCurl ? ? 反翻頁 ? ? ? ? ?私有API

cameraIrisHollowOpen ?開鏡頭 ? ?私有API

cameraIrisHollowClose ? 關(guān)鏡頭 ? 私有API

過渡方向參數(shù)

kCATransitionFromRight ? ? ?從右轉(zhuǎn)場

kCATransitionFromLeft ? ? ? ? 從左轉(zhuǎn)場

kCATransitionFromBottom ? ?從下轉(zhuǎn)場

kCATransitionFromTop ? ? ? ? ?從上轉(zhuǎn)場

上代碼 ?imageView 放了一張女神王祖賢的照片

//轉(zhuǎn)場動畫

-(void)maketransAnimation

{

CATransition* trans=[CATransition animation];

trans.repeatCount=1000;

// trans.type= kCATransitionPush;

trans.type=@"oglFlip";

trans.subtype=kCATransitionFromRight;

trans.duration=1.2;

trans.autoreverses=YES;

[self.imageView.layer addAnimation:trans forKey:nil];

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末稚补,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子慎菲,更是在濱河造成了極大的恐慌嫁蛇,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,627評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件露该,死亡現(xiàn)場離奇詭異睬棚,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)解幼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,180評論 3 399
  • 文/潘曉璐 我一進(jìn)店門抑党,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人撵摆,你說我怎么就攤上這事新荤。” “怎么了台汇?”我有些...
    開封第一講書人閱讀 169,346評論 0 362
  • 文/不壞的土叔 我叫張陵苛骨,是天一觀的道長。 經(jīng)常有香客問我苟呐,道長痒芝,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,097評論 1 300
  • 正文 為了忘掉前任牵素,我火速辦了婚禮严衬,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘笆呆。我一直安慰自己请琳,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 69,100評論 6 398
  • 文/花漫 我一把揭開白布赠幕。 她就那樣靜靜地躺著俄精,像睡著了一般。 火紅的嫁衣襯著肌膚如雪榕堰。 梳的紋絲不亂的頭發(fā)上竖慧,一...
    開封第一講書人閱讀 52,696評論 1 312
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼圾旨。 笑死踱讨,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的砍的。 我是一名探鬼主播痹筛,決...
    沈念sama閱讀 41,165評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼廓鞠!你這毒婦竟也來了味混?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,108評論 0 277
  • 序言:老撾萬榮一對情侶失蹤诫惭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蔓挖,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體夕土,經(jīng)...
    沈念sama閱讀 46,646評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,709評論 3 342
  • 正文 我和宋清朗相戀三年瘟判,在試婚紗的時候發(fā)現(xiàn)自己被綠了怨绣。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,861評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡拷获,死狀恐怖篮撑,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情匆瓜,我是刑警寧澤赢笨,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站驮吱,受9級特大地震影響茧妒,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜左冬,卻給世界環(huán)境...
    茶點故事閱讀 42,196評論 3 336
  • 文/蒙蒙 一桐筏、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧拇砰,春花似錦梅忌、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,698評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至瑰枫,卻和暖如春蹋笼,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,804評論 1 274
  • 我被黑心中介騙來泰國打工剖毯, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留圾笨,地道東北人。 一個月前我還...
    沈念sama閱讀 49,287評論 3 379
  • 正文 我出身青樓逊谋,卻偏偏與公主長得像擂达,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子胶滋,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,860評論 2 361

推薦閱讀更多精彩內(nèi)容