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的用于將多個layer tree操作批量化為渲染樹的原子更新的機制。 對layer tree的每個修改都需要事務作為其一部分。
CoreAnimation支持兩種事務,“顯式”事務和隱式事務。
顯式事務是程序員在修改層樹之前調用[CATransactionbegin],然后是[CATransaction commit]。
當層樹由沒有活動事務的線程修改時,CoreAnimation自動創建隱式事務
它們在線程的運行循環下一次迭代時自動提交。 在一些情況下(即,沒有運行循環,或者運行循環被阻塞),可能有必要使用顯式事務來及時地呈現樹更新。

+(void)begin;

Commit all changes made during the current transaction. Raises an exception if no current transaction exists.
提交當前事務期間進行的所有更改。 如果不存在當前事務,則引發異常。

+(void)commit;

Commits any extant implicit transaction. Will delay the actual commituntil any nested explicit transactions have completed.
提交任何現存的隱式事務。 將延遲實際的commituntil任何嵌套的顯式事務已經完成。

+ (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方法自動在修改共享狀態時獲得這一點,但是調用者可能需要鎖定多個操作以確保一致性。 鎖是一個遞歸自旋鎖(即不應長時間保持)。

+(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”每個線程事務屬性的訪問器。 定義添加到圖層的動畫的默認持續時間。 默認為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”每線程事務屬性的訪問器。 默認值為nil,當設置為非nil值時,添加到圖層的任何動畫都將此值設置為其“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”每線程事務屬性的訪問器。定義圖層的-actionForKey:方法是否用于為每個圖層屬性更改找到一個操作(也稱為implicitanimation)。 默認為NO,即啟用了隱式動畫。

+(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.
每個線程事務屬性的“completionBlock”訪問器。設置為非nil值后,一旦此事務組隨后添加的所有動畫都已完成(或已刪除),塊就被保證被調用(在主線程上) )。 如果在提交當前事務組之前沒有添加動畫(或者完成塊被設置為不同的值),則將立即調用該塊。 在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.
將任意鍵控數據與當前事務(即與當前線程)關聯。
嵌套事務具有嵌套數據作用域,即讀取一個鍵,搜索已設置它的最內層作用域,設置鍵總是將其設置在最內層作用域。
當前支持的事務屬性包括:“animationDuration”,“animationTimingFunction”,“completionBlock”,“disableActions”。 有關每個屬性的描述,請參閱上面的方法聲明。 嘗試將屬性設置為非文檔類型以外的類型具有未定義的結果。

+ (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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 背景 UIView實際是一個復合類型,CALayer是它內部實際承擔繪制顯示任務的部分。 當一個view的圖層(l...
    FindCrt閱讀 1,473評論 11 7
  • 一個月,竟然就這樣堅持下來,寫寫改改,對文字的情懷不減反增,今天最后一天,索性就寫寫我與文字的美麗邂逅吧…… ...
    清晨暮霧閱讀 665評論 0 0
  • 你好! 我是你,再有106天就十八周歲的西瓜,身高157體重110,突然就想給你寫封信,來記錄現在的心里感受,現在...
    可兒的西瓜cc閱讀 297評論 1 1
  • 你知道嗎?喬布斯很少坐下來靜思,而是不停地涂鴉以激發大腦創意。谷歌涂鴉團隊不停的為LOGO涂鴉,不斷拓展品牌價值。...
    小純說閱讀 405評論 2 4