Graphics Reference
In-Depth Information
//add a custom action
CATransition
*transition = [
CATransition
animation
];
transition.
type
=
kCATransitionPush
;
transition.
subtype
=
kCATransitionFromLeft
;
self
.colorLayer.
actions
=
@{
@"backgroundColor"
: transition
}
;
//add it to our view
[
self
.layerView.
layer
addSublayer
:
self
.colorLayer];
}
- (
IBAction
)changeColor
{
//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
;
}
@end
Figure 7.3
The color value animation implemented using a push transition