Graphics Programs Reference
In-Depth Information
#import "RotationAppDelegate.h"
#import "HeavyViewController.h"
@implementation RotationAppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Get the device object
UIDevice *device = [UIDevice currentDevice];
// Tell it to start monitoring the accelerometer for orientation
[device beginGeneratingDeviceOrientationNotifications];
// Get the notification center for the app
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// Add yourself as an observer
[nc addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:device];
HeavyViewController *hvc = [[HeavyViewController alloc] init];
[[self window] setRootViewController:hvc];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Build and run the application. It should autorotate when you rotate the device, as shown in
Figure 8.8 . (You can also run the application in the simulator and rotate it from the Hard-
ware menu or use the keyboard shortcuts Command-Right Arrow and Command-Left Ar-
row.)
Figure 8.8 Running rotated
 
Search WWH ::




Custom Search