首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIViewController的UIInterfaceOrientation

UIViewController的UIInterfaceOrientation
EN

Stack Overflow用户
提问于 2012-07-06 01:35:46
回答 3查看 1.1K关注 0票数 1

我尝试检查当前呈现的视图控制器的UIInterfaceOrientation,但由于某些原因,它总是返回横向。

代码语言:javascript
复制
 UIInterfaceOrientation currentOrientation = (UIInterfaceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
            if (currentOrientation == UIInterfaceOrientationPortrait){
                self.scrollView_.colMargin = 50;
            } else {
                self.scrollView_.colMargin = 130;
            }

知道为什么吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-07-06 01:44:19

您可以按如下方式检查方向:

代码语言:javascript
复制
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
    if( orientation == UIDeviceOrientationPortrait ) ...
票数 1
EN

Stack Overflow用户

发布于 2012-09-15 00:35:09

从iOS UIDevice类参考中:

orientation

返回设备的物理方向。(只读)

讨论

除非通过调用beginGeneratingDeviceOrientationNotifications.启用了方向通知,否则此属性的值始终返回0

所以你需要做一些类似的事情:

代码语言:javascript
复制
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

然后别忘了

代码语言:javascript
复制
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

when you viewDidUnload

票数 1
EN

Stack Overflow用户

发布于 2012-07-06 01:39:02

选角不是魔术。状态栏方向可以使用与界面方向不同的值。请改用当前视图控制器的self.interfaceOrientation属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11349557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档