官方文檔
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