Mac Developer Library

Developer

QuartzCore Framework Reference CATransaction Class Reference

Options
Deployment Target:

On This Page
Language:

CATransaction

CATransaction is the Core Animation mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to a layer tree must be part of a transaction. Nested transactions are supported. More...

Inheritance


Conforms To


Import Statement


import QuartzCore @import QuartzCore;

Availability


Available in OS X v10.5 and later.
  • Begin a new transaction for the current thread.

    Declaration

    Swift

    class func begin()

    Objective-C

    + (void)begin

    Discussion

    The transaction is nested within the thread’s current transaction, if there is one.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Commit all changes made during the current transaction.

    Declaration

    Swift

    class func commit()

    Objective-C

    + (void)commit

    Special Considerations

    Raises an exception if no current transaction exists.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

    See Also

    + begin
    + flush

  • Flushes any extant implicit transaction.

    Declaration

    Swift

    class func flush()

    Objective-C

    + (void)flush

    Discussion

    Delays the commit until any nested explicit transactions have completed.

    Flush is typically called automatically at the end of the current runloop, regardless of the runloop mode. If your application does not have a runloop, you must call this method explicitly.

    However, you should attempt to avoid calling flush explicitly. By allowing flush to execute during the runloop your application will achieve better performance, atomic screen updates will be preserved, and transactions and animations that work from transaction to transaction will continue to function.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns whether actions triggered as a result of property changes made within this transaction group are suppressed.

    Declaration

    Swift

    class func disableActions() -> Bool

    Objective-C

    + (BOOL)disableActions

    Return Value

    YEStrue if actions are disabled.

    Discussion

    This is a convenience method that returns the boolValue for the valueForKey: value returned by the kCATransactionDisableActions key.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • Sets whether actions triggered as a result of property changes made within this transaction group are suppressed.

    Declaration

    Swift

    class func setDisableActions(_ flag: Bool)

    Objective-C

    + (void)setDisableActions:(BOOL)flag

    Parameters

    flag

    YEStrue, if actions should be disabled.

    Discussion

    This is a convenience method that invokes setValue:forKey: with an NSNumber containing a YEStrue for the kCATransactionDisableActions key.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • Returns the completion block object.

    Declaration

    Swift

    class func completionBlock() -> (() -> Void)!

    Objective-C

    + (void (^)(void))completionBlock

    Discussion

    See setCompletionBlock: for a description of the role of the completion block object.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • Sets the completion block object.

    Declaration

    Swift

    class func setCompletionBlock(_ block: (() -> Void)!)

    Objective-C

    + (void)setCompletionBlock:(void (^)(void))block

    Parameters

    block

    A block object called when animations for this transaction group are completed.

    The block object takes no parameters and returns no value.

    Discussion

    The completion block object that is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have 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.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

  • Attempts to acquire a recursive spin-lock lock, ensuring that returned layer values are valid until unlocked.

    Declaration

    Swift

    class func lock()

    Objective-C

    + (void)lock

    Discussion

    Core Animation uses a data model that promises not to corrupt the internal data structures when called from multiple threads concurrently, but not that data returned is still valid if the property was valid on another thread. By locking during a transaction you can ensure data that is read, modified, and set is correctly managed.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

    See Also

    + unlock

  • Relinquishes a previously acquired transaction lock.

    Declaration

    Swift

    class func unlock()

    Objective-C

    + (void)unlock

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.6 and later.

    See Also

    + lock

  • Sets the arbitrary keyed-data for the specified key.

    Declaration

    Swift

    class func setValue(_ anObject: AnyObject!, forKey key: String!)

    Objective-C

    + (void)setValue:(id)anObject forKey:(NSString *)key

    Parameters

    anObject

    The value for the key identified by key.

    key

    The name of one of the receiver's properties.

    Discussion

    Nested transactions have nested data scope; setting a key always sets it in the innermost scope.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • Returns the arbitrary keyed-data specified by the given key.

    Declaration

    Swift

    class func valueForKey(_ key: String!) -> AnyObject!

    Objective-C

    + (id)valueForKey:(NSString *)key

    Parameters

    key

    The name of one of the receiver's properties.

    Return Value

    The value for the data specified by the key.

    Discussion

    Nested transactions have nested data scope. Requesting a value for a key first searches the innermost scope, then the enclosing transactions.

    Import Statement

    import QuartzCore

    Availability

    Available in OS X v10.5 and later.

  • These constants define the property keys used by valueForKey: and setValue:forKey:.

    Declaration

    Swift

    let kCATransactionAnimationDuration: NSString! let kCATransactionDisableActions: NSString! let kCATransactionAnimationTimingFunction: NSString! let kCATransactionCompletionBlock: NSString!

    Objective-C

    NSString * const kCATransactionAnimationDuration; NSString * const kCATransactionDisableActions; NSString * const kCATransactionAnimationTimingFunction; NSString * const kCATransactionCompletionBlock;

    Constants

    • kCATransactionAnimationDuration

      kCATransactionAnimationDuration

      Duration, in seconds, for animations triggered within the transaction group. The value for this key must be an instance of NSNumber.

      Available in OS X v10.5 and later.

    • kCATransactionDisableActions

      kCATransactionDisableActions

      If YEStrue, implicit actions for property changes made within the transaction group are suppressed. The value for this key must be an instance of NSNumber.

      Available in OS X v10.5 and later.

    • kCATransactionAnimationTimingFunction

      kCATransactionAnimationTimingFunction

      An instance of CAMediaTimingFunction that overrides the timing function for all animations triggered within the transaction group.

      Available in OS X v10.6 and later.

    • kCATransactionCompletionBlock

      kCATransactionCompletionBlock

      A completion block object that is guaranteed to be called (on the main thread) as soon as all animations subsequently added by this transaction group have completed (or have 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.

      Available in OS X v10.6 and later.

    Import Statement