Graphics Reference
In-Depth Information
{
[
super
viewDidLoad
];
//create a path
UIBezierPath
*bezierPath = [[
UIBezierPath
alloc
]
init
];
[bezierPath
moveToPoint
:
CGPointMake
(
0
,
150
)];
[bezierPath
addCurveToPoint
:
CGPointMake
(
300
,
150
)
controlPoint1
:
CGPointMake
(
75
,
0
)
controlPoint2
:
CGPointMake
(
225
,
300
)];
//draw the path using a CAShapeLayer
CAShapeLayer
*pathLayer = [
CAShapeLayer
layer
];
pathLayer.
path
= bezierPath.
CGPath
;
pathLayer.
fillColor
= [
UIColor
clearColor
].
CGColor
;
pathLayer.
strokeColor
= [
UIColor
redColor
].
CGColor
;
pathLayer.
lineWidth
=
3.0f
;
[
self
.containerView.
layer
addSublayer
:pathLayer];
//add the ship
CALayer
*shipLayer = [
CALayer
layer
];
shipLayer.
frame
=
CGRectMake
(
0
,
0
,
64
,
64
);
shipLayer.
position
=
CGPointMake
(
0
,
150
);
shipLayer.
contents
= (
__bridge
id
)[
UIImage
imageNamed
:
@"Ship.png"
].
CGImage
;
[
self
.containerView.
layer
addSublayer
:shipLayer];
//create the keyframe animation
CAKeyframeAnimation
*animation = [
CAKeyframeAnimation
animation
];
animation.
keyPath
=
@"position"
;
animation.
duration
=
4.0
;
animation.
path
= bezierPath.
CGPath
;
[shipLayer
addAnimation
:animation
forKey
:
nil
];
}
@end