NSLog
问题是,当我第一次运行它时,我的应用程序不会显示里面的日志。但是当我将方向更改为横向时,文本出现了。顺便说一下,应用程序的默认视图是纵向的。
viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
}
但是如果我在我的viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSTimeInterval duration = 0.0;
[self willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
它可以顺利地显示日志。
问题是,我是否以正确的方式显示日志?
我的willAnimateRotationToInterfaceOrientation:toInterfaceOrientation:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
CGFloat height = CGRectGetHeight([[UIScreen mainScreen] bounds]);
CGFloat width = CGRectGetWidth([[UIScreen mainScreen] bounds]);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
NSLog(@"iPhone/Portrait");
break;
case UIInterfaceOrientationLandscapeLeft:
NSLog(@"iPhone/Landscape/Left");
break;
case UIInterfaceOrientationLandscapeRight:
NSLog(@"iPhone/Landscape/Right");
break;
default:
break;
}
}
else {
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
NSLog(@"iPad/Portrait");
break;
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(@"iPad/Upside Down");
break;
case UIInterfaceOrientationLandscapeLeft:
NSLog(@"iPad/Landscape/Left");
break;
case UIInterfaceOrientationLandscapeRight:
NSLog(@"iPad/Landscape/Right");
break;
default:
break;
}
}
}