runAnimationGroup(_:completionHandler:)
Allows you to specify a completion block body after the set of animation actions whose completion will trigger the completion block.
Declaration
class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void, completionHandler: (@Sendable () -> Void)? = nil)class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void) asyncParameters
- changes:
A block object containing animations for this transaction group.
The
contextparameter passes the thread’s currentNSAnimationContextto the Block as a convenience, so code within the Block that wants to change or query properties of the currentcontextdoes not have to call Current.The block object returns no value.
- completionHandler:
A Block object called when animations for this transaction group are completed.
The Block object takes no parameters and returns no value.
Discussion
Using this method allows you to more naturally group animations and an completion Block.
An example use is as follows. Using this method you would write the following code fragment:
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
// Start some animations.
[[myView animator] setFrameSize:newViewSize];
[[myWindow animator] setFrame:newWindowFrame display:YES];
} completionHandler:^{
// This block will be invoked when all of the animations
// started above have completed or been cancelled.
NSLog(@"All done!");
}];The above code is semantically equivalent to the following:
[NSAnimationContext beginGrouping];
[NSAnimationContext setCompletionHandler:^{
// This block will be invoked when all of the animations
// started below have completed or been cancelled.
NSLog(@"All done!");
}];
// Start some animations.
[[myView animator] setFrameSize:newViewSize];
[[myWindow animator] setFrame:newWindowFrame display:YES];
[NSAnimationContext endGrouping];