In this app, unlike the previous one, it is entirely appropriate for the (big green) view to occupy the entire window. The status bar has a transparent background and is in front of the view.
The
CADisplayLink
in the
ViewController
calls the
move:
method of the
View
every time the hardware refreshes the display.
It would be a waste of processing power to call
move:
more frequently than the hardware refreshes the display.
Since class
View
has no
drawRect:
method
(other than the one that does nothing that is inherited from its base class
UIView
),
it is not necessary to call
[self setNeedsDisplay]
.
main.m
PongAppDelegate
ViewController
View
Pong-Info.plist
ViewController.h
must import
QuartzCore/QuartzCore.h
in order to mention
CADisplayLink
.
Add an Initial Interface Orientation to
Pong-Info.plist
(see below).
In Supporting Files in the Project navigator, open
Pong-Info.plist
.
Initial interface orientation: String Landscape (left home button)
See
Launching
in Landscape Mode.
To tell you the truth, I just control-click on
Pong-Info.plist
Open As → Source Code.
//In application:didFinishLaunchingWithOptions: CGRect bounds = [UIScreen mainScreen].bounds; NSLog(@"(%g, %g) %g × %g)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height ); CGRect applicationFrame = [UIScreen mainScreen].applicationFrame; NSLog(@"(%g, %g) %g × %g)", applicationFrame.origin.x, applicationFrame.origin.y, applicationFrame.size.width, applicationFrame.size.height );
2013-11-12 21:11:39.439 Pong[13989:a0b] (0, 0) 320 × 568) 2013-11-12 21:11:39.440 Pong[13989:a0b] (20, 0) 300 × 568)
initWithFrame:
method of class
View
,
decrease (or increase)
the distances
dx
and
dy
.
NSLog
in the
move:
method of the
View
to find the interval in seconds between each refresh of the screen.
On the simulator on my Mac, it was 60 times per second
(except for the very first interval).
2013-11-12 21:22:47.037 Pong[14031:a0b] 166640.820880753 2013-11-12 21:22:47.051 Pong[14031:a0b] 166640.834562509 2013-11-12 21:22:47.068 Pong[14031:a0b] 166640.851272424 2013-11-12 21:22:47.084 Pong[14031:a0b] 166640.868001945 2013-11-12 21:22:47.101 Pong[14031:a0b] 166640.884619043 2013-11-12 21:22:47.118 Pong[14031:a0b] 166640.901141977Open the Macintosh Terminal window and print the reciprocal of the interval.
bc -l scale=5 1 / (166640.901141977 - 166640.884619043) 60.52193 control-dDo the iPhone tech specs give the refresh rate? It was 68 times per second on my Motorola Android phone.