iphone - NSLog InterfaceRotation 在模拟器上不起作用?

标签 iphone objective-c ios uiviewcontroller

我想知道为什么在 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/

相关文章:

javascript - 对 native 选择器进行样式设置-特别是文本对齐(iOS)

iphone - 如何将数据发送到网络服务器并知道它来自某个应用程序?

iphone - 在 canAuthenticateAgainstProtectionSpace 中检查公钥

php - 无法显示从新服务器下载文件的进度(在以前的服务器上工作)

objective-c - Cocoa 网络流和垃圾收集器

ios - 哪个 iOS 引用可以在 iPad mini 上进行实时视频播放?

ios - 焦点上的 UITextField 或使用 objective-c 开始编辑输入字段背景颜色更改

iPhone - 根据文字调整UILabel宽度

ios - 在 collectionview 单元格内的 ImageView 变得可见后对其进行动画处理

ios - 为 UISegmentedControl 定义点击事件