如何检测设备方向与界面方向不同?
问题描述:
最初的UINavigationController
(Navigator
)的子类是根控制器和它支持所有取向。 子类覆盖supportedInterfaceOrientations
,并提供属性来设置支持什么方向。如何检测设备方向与界面方向不同?
Navigator
的导航堆栈(UITableViewContreller
的子类)的根视图控制器控制支持的方向(取决于哪个视图控制器位于堆栈顶部)。它设置在didSelectRowAtIndexPath
覆盖Navigator
S取向性。
如果在设备处于不同方向时进行转换(因为当前视图不支持它并且这不是一种假定的交互方式),并且新视图支持该设备方向,所以视图保持不同于设备方向。 然后人们需要旋转设备并将其移回到正确的方向。
这是如果有人出于某种原因将持有的景观模式的设备在联系人应用程序,但突然它的一个子视图将支持横向和不为纵向和横向然后旋转装置自动旋转。问题是如何实现它?
答
在每个方法使用此:
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
}
else
{
}
或检查[[UIScreen mainScreen] bounds]
答
我觉得这是要你想要的。
要获得设备的方向:
[[UIDevice currentDevice] orientation];
要得到的意见电流方向显示:
[UIApplication sharedApplication].statusBarOrientation;
答
添加这个方法将你的UINavigationController子类:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return;
if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) {
//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
}
}
(在SF上找到它,但无法找到该问题的链接)
基于视图框的大小,你可以识别横向模式或纵向模式 – 2013-03-14 13:39:53
我的意思是,你需要在每一个函数来检查帧大小的 – 2013-03-14 13:46:32