Graphics Reference
In-Depth Information
//randomize the layer background color
CGFloat red = arc4random () / ( CGFloat ) INT_MAX ;
CGFloat green = arc4random () / ( CGFloat ) INT_MAX ;
CGFloat blue = arc4random () / ( CGFloat ) INT_MAX ;
self . colorLayer . backgroundColor = [ UIColor colorWithRed :red
green :green
blue :blue
alpha : 1.0 ]. CGColor ;
//commit the transaction
[ CATransaction commit ];
}
Figure 7.2 A rotation animation applied after the color fade has finished
Notice that our rotation animation is much faster than our color fade animation. That's
because the completion block that applies the rotation animation is executed after the color
fade animation's transaction has been committed and popped off the stack. It is, therefore,
using the default transaction, with the default animation duration of 0.25 seconds.
Layer Actions
Now let's try an experiment: Instead of animating a standalone sublayer, we'll try directly
animating the backing layer of our view. Listing 7.4 shows an adapted version of the code
 
Search WWH ::




Custom Search