Wednesday, June 12, 2013

CATransaction setDisableActions example in Objective C (iOS).

CATransaction setDisableActions

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

+ (void)setDisableActions:(BOOL)flag

Parameters
flag
YES, if actions should be disabled.

Discussion of [CATransaction setDisableActions]
This is a convenience method that invokes setValue:forKey: with an NSNumber containing a YES for the kCATransactionDisableActions key.

CATransaction setDisableActions example.
[CATransaction begin];
[CATransaction setAnimationDuration: 1.0/30.0];
[CATransaction setDisableActions: TRUE];
//Put layer changes you want to take place without animation here.
[CATransaction commit];

Example of [CATransaction setDisableActions].
- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel {
    BOOL previousDisableActions = [CATransaction disableActions];
    [CATransaction setDisableActions:NO];

    // Begin animation here.

    [CATransaction setDisableActions:previousDisableActions];
}

CATransaction setDisableActions example.
[CATransaction setCompletionBlock:^{
    //Readjust button frame for touch area

    CGRect frameRect = self.frame;
    frameRect.origin.x = frameRect.origin.x - offset;
    frameRect.size.width = frameRect.size.width + offset;
    self.frame = frameRect;

    [CATransaction setDisableActions:YES];
    for(CALayer *layer in self.layer.sublayers){
        CGRect rect = layer.frame;
        rect.origin.x = rect.origin.x+offset;
        layer.frame = rect;
    }
    [CATransaction commit];

}];

End of CATransaction setDisableActions example article.