请帮帮我。我有以下方法:
-(void) getCurrentOrientation{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait){
NSLog(@"portrait");
} else if(orientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"LandscapeRight");
} else if(orientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LandscapeLeft");
}
}
但是当我在viewDidLoad中调用getCurrentOrientation时,会出现以下问题。
- (void)viewDidLoad
{
[super viewDidLoad];
[self getCurrentOrientation];
}
NSLog是空的。有什么问题吗? 我也尝试了
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if ( ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait)) {
NSLog(@"portrait");
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"LandscapeRight");
}
}
但是那个varint也是空的。
我需要知道用户启动应用程序的方向!
请给我任何建议。