检测iOS设备方向锁定 [英] Detect iOS device orientation lock

查看:96
本文介绍了检测iOS设备方向锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检查设备方向是否在iOS中被锁定?我在UIDevice中什么都看不到。我知道这应该对应用程序透明。但是如果方向被锁定,我想改变显示内容的方式(正如Youtube应用程序所做的那样;它会锁定到横向而不是纵向)。这必须是可能的。

How can I programmatically check whether the device orientation is locked in iOS? I see nothing in UIDevice. I know that this is supposed to be transparent to the app. But I'd like to change the way I display content if the orientation is locked (as the Youtube app does; it locks to landscape rather than portrait). This must be possible.

推荐答案

无法检测方向是否被锁定。 YouTube应用不会锁定横向,它只是横向显示电影,但是当您旋转iPhone时,电影也会旋转(如果没有方向锁定)。

There's no way how to detect if orientation is locked or not. YouTube app doesn't lock to landscape, it just displays movie in landscape orientation, but when you rotate your iPhone, movie rotates as well (if there's no orientation lock).

IOW方向锁定由系统处理,对您的应用程序透明。

IOW orientation lock is handled by system, transparent to your application.

如果您想要实现此功能 - 即使iPhone处于显示状态,只需以横向模式显示您的视图纵向模式,稍后启用视图旋转。它的行为方式与YouTube应用相同。

If you want to achieve this functionality - just display your view in landscape mode even if the iPhone is in portrait mode and later enable rotation of your view. It will behave in the same way as YouTube app.

评论更新:

.h

BOOL rotationEnabled;

.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
  return rotationEnabled || ( toInterfaceOrientation == UIInterfaceOrientationLandscapeRight );
}

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  rotationEnabled = YES;
}

这篇关于检测iOS设备方向锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆