Graphics Reference
In-Depth Information
CATransform3D NSValue
id obj = [NSValue
valueWithCATransform3D:transform);
CGImageRef
id
id obj = (__bridge id)imageRef;
CGColorRef
id
id obj = (__bridge id)colorRef;
The
fromValue
,
toValue
, and
byValue
properties can be used in various combinations, but
you should not specify all three at once because that could result in a contradiction. For
example, if you were to specify a
fromValue
of 2, a
toValue
of 4, and a
byValue
of 3,
Core Animation would not know whether the final value should be 4 (as specified by
toValue
) or 5 (
fromValue
+
byValue
). The exact rules around how these properties can be
used are neatly documented in the
CABasicAnimation
header file, so we won't repeat them
here. In general, you will only need to specify either the
toValue
or
byValue
; the other
values can be determined automatically from context.
Let's try an example: We'll modify our color fade animation from Chapter 7, “Implicit
Animations,” to use an explicit
CABasicAnimation
instead of an implicit one. Listing 8.1
shows the code.
Listing 8.1
Setting the Layer Background Color with
CABasicAnimation
@interface
ViewController ()
@property
(
nonatomic
,
weak
)
IBOutlet
UIView
*layerView;
@property
(
nonatomic
,
strong
)
IBOutlet
CALayer
*colorLayer;
@end
@implementation
ViewController
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
//create sublayer
self
.colorLayer = [
CALayer
layer
];
self
.colorLayer.
frame
=
CGRectMake
(
50.0f
,
50.0f
,
100.0f
,
100.0f
);
self
.colorLayer.
backgroundColor
= [
UIColor
blueColor
].
CGColor
;
//add it to our view
[
self
.layerView.
layer
addSublayer
:
self
.colorLayer];
}
- (
IBAction
)changeColor
{
//create a new random color