我有一个带有选项卡栏的应用程序,每个选项卡上都有导航控制器.当用户摇动设备时,导航控制器中将显示一个UIImageView作为子视图.但UIImageView必须包含一个特殊的图像,这取决于设备的当前方向.

如果我只写

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
   if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
   //Code
   }
   else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
   //Code
   }
}

如果用户在摇晃前旋转设备,视图就会变得疯狂.

Is there a method to get iPhones current orientation?

推荐答案

按照第here条的规定,使用[[UIDevice currentDevice] orientation]方法.

Objective-c相关问答推荐

MKMapView 上的 UIPanGestureRecognizer?

我应该为 memcpy 和 realloc 包含什么标题?

UITableView/UITableViewCell 点击事件响应?

如何在for (id item in items)objective-c 循环中获取数组索引?

如何使用格式化占位符本地化字符串?

pathForResource 返回 null

如何创建 NSIndexPath:indexPathWithIndexes:length 所需的索引:

UIRefreshControl iOS 6 xcode

使用 [NSBundle mainBundle] pathForResource: ofType:inDirectory: 访问文件

反编译 Objective-C 库

添加自定义 initWith?

StoryBoard 助理编辑器停止显示相关文件

iPhone - 时区便利方法之间的差异

未知类型名称类;您指的是 'Class' 吗?

distanceFromLocation - 计算两点之间的距离

在 switch 语句中使用 NSString

在我滚动之前,数据不会加载到 UITableView 中

字符串常量和字符串文字有什么区别?

如何删除 UIToolBar 上的顶部边框

Objective C 消息分发机制