为什么我允许访问orientationChanged:
而不在.h
文件中声明它?我在 Apple 的文档中找不到该方法,所以我认为它不是继承的方法。
#import <UIKit/UIKit.h>
@interface RotationAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "RotationAppDelegate.h"
@implementation RotationAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIDevice *device = [UIDevice currentDevice];
[device beginGeneratingDeviceOrientationNotifications];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:device];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)orientationChanged:(NSNotification *)note {
NSLog(@"oriendtationChanged: %i", [[note object] orientation]);
}