Graphics Reference
In-Depth Information
@end
@implementation
ViewController
- (
void
)viewDidLoad
{
[
super
viewDidLoad
];
//create a path
self
.bezierPath = [[
UIBezierPath
alloc
]
init
];
[
self
.bezierPath
moveToPoint
:
CGPointMake
(
0
,
150
)];
[
self
.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
=
self
.bezierPath.
CGPath
;
pathLayer.
fillColor
= [
UIColor
clearColor
].
CGColor
;
pathLayer.
strokeColor
= [
UIColor
redColor
].
CGColor
;
pathLayer.
lineWidth
=
3.0f
;
[
self
.containerView.
layer
addSublayer
:pathLayer];
//add the ship
self
.shipLayer = [
CALayer
layer
];
self
.shipLayer.
frame
=
CGRectMake
(
0
,
0
,
64
,
64
);
self
.shipLayer.
position
=
CGPointMake
(
0
,
150
);
self
.shipLayer.
contents
= (
__bridge
id
)[
UIImage
imageNamed
:
@"Ship.png"
].
CGImage
;
[
self
.containerView.
layer
addSublayer
:
self
.shipLayer];
//set initial values
[
self
updateSliders
];
}
- (
IBAction
)updateSliders
{
CFTimeInterval
timeOffset =
self
.timeOffsetSlider.
value
;
self
.
timeOffsetLabel.
text
= [
NSString
stringWithFormat
:
@"%0.2f"
,
timeOffset];
float
speed =
self
.speedSlider.
value
;
self
.speedLabel.
text
= [
NSString
stringWithFormat
:
@"%0.2f"
, speed];
}
- (
IBAction
)play