我想知道为什么在 iOS 模拟器上通过跟踪我的 UIViewController 中的代码进行测试时没有控制台输出 - 它仅通过在设备上进行测试进行跟踪。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"willRotateToInterfaceOrientation: ", toInterfaceOrientation);
}
我如何打印出 UIInterfaceOrientation 值(枚举类型)? 如果能得到你的帮助就太好了……谢谢
最佳答案
格式说明符在哪里?
UIInterfaceOrientation
是一个 typedef enum
,而不是一个对象,因此您不能使用 %@
作为格式说明符。
应该是这样的:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"willRotateToInterfaceOrientation: %d", toInterfaceOrientation);
}
如果您真的需要这种“ pretty-print ”功能,您可以通过开关
运行它,如下所示:
NSString *orient;
switch(toInterfaceOrientation) {
case UIInterfaceOrientationLandscapeRight:
orient = @"UIInterfaceOrientationLandscapeRight";
break;
case UIInterfaceOrientationLandscapeLeft:
orient = @"UIInterfaceOrientationLandscapeLeft";
break;
case UIInterfaceOrientationPortrait:
orient = @"UIInterfaceOrientationPortrait";
break;
case UIInterfaceOrientationPortraitUpsideDown:
orient = @"UIInterfaceOrientationPortraitUpsideDown";
break;
default:
orient = @"Invalid orientation";
}
NSLog(@"willRotateToInterfaceOrientation: %@", orient);
关于iphone - NSLog InterfaceRotation 在模拟器上不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4382452/