CATransaction

官方文檔

Transactions are CoreAnimation's mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to the layer tree requires a transaction to be part of.

CoreAnimation supports two kinds of transactions, "explicit" transactions and "implicit" transactions.

Explicit transactions are where the programmer calls [CATransactionbegin] before modifying the layer tree, and [CATransaction commit] afterwards.
Implicit transactions are created automatically by CoreAnimation when the layer tree is modified by a thread without an active transaction.
They are committed automatically when the thread's run-loop next iterates. In some circumstances (i.e. no run-loop, or the run-loop is blocked) it may be necessary to use explicit transactions to get timely render tree updates.

谷歌翻譯:
Transactions是CoreAnimation的用于將多個(gè)layer tree操作批量化為渲染樹的原子更新的機(jī)制。 對(duì)layer tree的每個(gè)修改都需要事務(wù)作為其一部分挟秤。
CoreAnimation支持兩種事務(wù)纱新,“顯式”事務(wù)和隱式事務(wù)创淡。
顯式事務(wù)是程序員在修改層樹之前調(diào)用[CATransactionbegin],然后是[CATransaction commit]蛇券。
當(dāng)層樹由沒(méi)有活動(dòng)事務(wù)的線程修改時(shí),CoreAnimation自動(dòng)創(chuàng)建隱式事務(wù)
它們?cè)诰€程的運(yùn)行循環(huán)下一次迭代時(shí)自動(dòng)提交斩芭。 在一些情況下(即,沒(méi)有運(yùn)行循環(huán)乐疆,或者運(yùn)行循環(huán)被阻塞)划乖,可能有必要使用顯式事務(wù)來(lái)及時(shí)地呈現(xiàn)樹更新。

+(void)begin;

Commit all changes made during the current transaction. Raises an exception if no current transaction exists.
提交當(dāng)前事務(wù)期間進(jìn)行的所有更改挤土。 如果不存在當(dāng)前事務(wù)琴庵,則引發(fā)異常。

+(void)commit;

Commits any extant implicit transaction. Will delay the actual commituntil any nested explicit transactions have completed.
提交任何現(xiàn)存的隱式事務(wù)仰美。 將延遲實(shí)際的commituntil任何嵌套的顯式事務(wù)已經(jīng)完成迷殿。

+ (void)flush;

Methods to lock and unlock the global lock. Layer methods automatically
obtain this while modifying shared state, but callers may need to lock around multiple operations to ensure consistency. The lock is a recursive spin-lock (i.e shouldn't be held for extended periods).
鎖定和解鎖全局鎖的方法。 Layer方法自動(dòng)在修改共享狀態(tài)時(shí)獲得這一點(diǎn)咖杂,但是調(diào)用者可能需要鎖定多個(gè)操作以確保一致性庆寺。 鎖是一個(gè)遞歸自旋鎖(即不應(yīng)長(zhǎng)時(shí)間保持)。

+(void)lock;
+(void)unlock;

Accessors for the "animationDuration" per-thread transaction property. Defines the efault duration of animations added to layers. Defaults to 1/4s.
“animationDuration”每個(gè)線程事務(wù)屬性的訪問(wèn)器诉字。 定義添加到圖層的動(dòng)畫的默認(rèn)持續(xù)時(shí)間懦尝。 默認(rèn)為1 / 4s。

+(CFTimeInterval)animationDuration;
+(void)setAnimationDuration:(CFTimeInterval)dur;

Accessors for the "animationTimingFunction" per-thread transaction property. The default value is nil, when set to a non-nil value any animations added to layers will have this value set as their "timingFunction" property. Added in Mac OS X 10.6.
“animationTimingFunction”每線程事務(wù)屬性的訪問(wèn)器壤圃。 默認(rèn)值為nil陵霉,當(dāng)設(shè)置為非nil值時(shí),添加到圖層的任何動(dòng)畫都將此值設(shè)置為其“timingFunction”屬性伍绳。 在Mac OS X 10.6中添加撩匕。

+(nullable CAMediaTimingFunction *)animationTimingFunction;
+(void)setAnimationTimingFunction:(nullable CAMediaTimingFunction *)function;

Accessors for the "disableActions" per-thread transaction property.Defines whether or not the layer's -actionForKey: method is used to find an action (aka. implicitanimation) for each layer property change. Defaults to NO, i.e.implicitanimations enabled.
“disableActions”每線程事務(wù)屬性的訪問(wèn)器。定義圖層的-actionForKey:方法是否用于為每個(gè)圖層屬性更改找到一個(gè)操作(也稱為implicitanimation)墨叛。 默認(rèn)為NO止毕,即啟用了隱式動(dòng)畫。

+(BOOL)disableActions;
+(void)setDisableActions:(BOOL)flag;

Accessors for the "completionBlock" per-thread transaction property.Once set to a non-nil value the block is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or been removed). If no animations are added before the current transaction group is committed (or the completion block is set to a different value), the block will be invoked immediately. Added in Mac OS X 10.6.
每個(gè)線程事務(wù)屬性的“completionBlock”訪問(wèn)器漠趁。設(shè)置為非nil值后扁凛,一旦此事務(wù)組隨后添加的所有動(dòng)畫都已完成(或已刪除),塊就被保證被調(diào)用(在主線程上) )闯传。 如果在提交當(dāng)前事務(wù)組之前沒(méi)有添加動(dòng)畫(或者完成塊被設(shè)置為不同的值)谨朝,則將立即調(diào)用該塊。 在Mac OS X 10.6中添加。

#if __BLOCKS__
+ (nullable void (^)(void))completionBlock;
+ (void)setCompletionBlock:(nullable void (^)(void))block;
#endif

Associate arbitrary keyed-data with the current transaction (i.e. with the current thread).
Nested transactions have nested data scope, i.e. reading a key searches for the innermost scope that has set it, setting a key always sets it in the innermost scope.
Currently supported transaction properties include:"animationDuration","animationTimingFunction", "completionBlock", "disableActions". See method declarations above for descriptions of each property. Attempting to set a property to a type other than its document type has an undefined result.
將任意鍵控?cái)?shù)據(jù)與當(dāng)前事務(wù)(即與當(dāng)前線程)關(guān)聯(lián)字币。
嵌套事務(wù)具有嵌套數(shù)據(jù)作用域则披,即讀取一個(gè)鍵,搜索已設(shè)置它的最內(nèi)層作用域洗出,設(shè)置鍵總是將其設(shè)置在最內(nèi)層作用域士复。
當(dāng)前支持的事務(wù)屬性包括:“animationDuration”,“animationTimingFunction”翩活,“completionBlock”阱洪,“disableActions”。 有關(guān)每個(gè)屬性的描述菠镇,請(qǐng)參閱上面的方法聲明冗荸。 嘗試將屬性設(shè)置為非文檔類型以外的類型具有未定義的結(jié)果。

+ (nullable id)valueForKey:(NSString *)key;
+ (void)setValue:(nullable id)anObject forKey:(NSString *)key;
/** Transaction property ids. **/

CA_EXTERN NSString * const kCATransactionAnimationDuration
    CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
CA_EXTERN NSString * const kCATransactionDisableActions
    CA_AVAILABLE_STARTING (10.5, 2.0, 9.0, 2.0);
CA_EXTERN NSString * const kCATransactionAnimationTimingFunction
    CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString * const kCATransactionCompletionBlock
    CA_AVAILABLE_STARTING (10.6, 4.0, 9.0, 2.0);

NS_ASSUME_NONNULL_END
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末利耍,一起剝皮案震驚了整個(gè)濱河市蚌本,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌隘梨,老刑警劉巖魂毁,帶你破解...
    沈念sama閱讀 218,204評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異出嘹,居然都是意外死亡席楚,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門税稼,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)烦秩,“玉大人,你說(shuō)我怎么就攤上這事郎仆≈混簦” “怎么了?”我有些...
    開封第一講書人閱讀 164,548評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵扰肌,是天一觀的道長(zhǎng)抛寝。 經(jīng)常有香客問(wèn)我,道長(zhǎng)曙旭,這世上最難降的妖魔是什么蘑拯? 我笑而不...
    開封第一講書人閱讀 58,657評(píng)論 1 293
  • 正文 為了忘掉前任桐罕,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘收厨。我一直安慰自己驹暑,他們只是感情好揪垄,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著较沪,像睡著了一般。 火紅的嫁衣襯著肌膚如雪失仁。 梳的紋絲不亂的頭發(fā)上尸曼,一...
    開封第一講書人閱讀 51,554評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音萄焦,去河邊找鬼控轿。 笑死,一個(gè)胖子當(dāng)著我的面吹牛楷扬,可吹牛的內(nèi)容都是我干的解幽。 我是一名探鬼主播贴见,決...
    沈念sama閱讀 40,302評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼烘苹,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了片部?” 一聲冷哼從身側(cè)響起镣衡,我...
    開封第一講書人閱讀 39,216評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎档悠,沒(méi)想到半個(gè)月后廊鸥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,661評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡辖所,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評(píng)論 3 336
  • 正文 我和宋清朗相戀三年惰说,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片缘回。...
    茶點(diǎn)故事閱讀 39,977評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡吆视,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出酥宴,到底是詐尸還是另有隱情啦吧,我是刑警寧澤,帶...
    沈念sama閱讀 35,697評(píng)論 5 347
  • 正文 年R本政府宣布拙寡,位于F島的核電站授滓,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏肆糕。R本人自食惡果不足惜般堆,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望诚啃。 院中可真熱鬧郁妈,春花似錦、人聲如沸绍申。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至胃碾,卻和暖如春涨享,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背仆百。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工厕隧, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人俄周。 一個(gè)月前我還...
    沈念sama閱讀 48,138評(píng)論 3 370
  • 正文 我出身青樓吁讨,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親峦朗。 傳聞我的和親對(duì)象是個(gè)殘疾皇子建丧,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評(píng)論 2 355

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

  • 背景 UIView實(shí)際是一個(gè)復(fù)合類型,CALayer是它內(nèi)部實(shí)際承擔(dān)繪制顯示任務(wù)的部分波势。 當(dāng)一個(gè)view的圖層(l...
    FindCrt閱讀 1,458評(píng)論 11 7
  • 一個(gè)月翎朱,竟然就這樣堅(jiān)持下來(lái),寫寫改改尺铣,對(duì)文字的情懷不減反增拴曲,今天最后一天,索性就寫寫我與文字的美麗邂逅吧…… ...
    清晨暮霧閱讀 640評(píng)論 0 0
  • 你好凛忿! 我是你澈灼,再有106天就十八周歲的西瓜,身高157體重110店溢,突然就想給你寫封信叁熔,來(lái)記錄現(xiàn)在的心里感受,現(xiàn)在...
    可兒的西瓜cc閱讀 289評(píng)論 1 1
  • 你知道嗎逞怨?喬布斯很少坐下來(lái)靜思者疤,而是不停地涂鴉以激發(fā)大腦創(chuàng)意。谷歌涂鴉團(tuán)隊(duì)不停的為L(zhǎng)OGO涂鴉叠赦,不斷拓展品牌價(jià)值驹马。...
    小純說(shuō)閱讀 386評(píng)論 2 4