旋转视图时不触发 UIInterfaceOrientationIsLandscape
我正在尝试使我的应用程序能够横向和纵向工作。我在所有视图控制器中安装了正确的方法,并且当 ipad 模拟器旋转时此代码会触发,但总是触发纵向。景观 IF 子句永远不会被触发。我可能做错了什么?
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation {
NSLog(@"******* ROTATING ******");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
NSLog(@"ROTATING View Landscape ******");
} else if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
NSLog(@"ROTATING View Portrait ******");
}
}
}
I am trying to make my app work in landscape orientation as well as portrait. I have the proper methods installed in all my viewcontrollers and this code triggers when the ipad simulator is rotated, but always triggers portrait. The landscape IF clause never gets triggered. What could I be doing wrong?
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)InterfaceOrientation {
NSLog(@"******* ROTATING ******");
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
NSLog(@"ROTATING View Landscape ******");
} else if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
NSLog(@"ROTATING View Portrait ******");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
设备和界面方向似乎是不同的东西。我在 Apple 网站上找到了使用 UIDeviceOrientation 执行此操作的方法。使用此测试,当我旋转模拟器和我的 iPad 设备时,我会得到正确的触发器。
Device and interface orientation appear to be different things. I found on Apple's site the way to do this using UIDeviceOrientation. Using this test I get the proper triggers when i rotate the simulator and my ipad device.
我发现检测 iPhone/iPad 当前设备方向的最可靠方法是使用
statusBarOrientation
属性,如下所示:如果您使用它而不是
self.interfaceOrientation< /code>,你的代码可以工作吗?
I've found that the most reliable way to detect the current device orientation of an iPhone/iPad is to use the
statusBarOrientation
property, like so:If you use that instead of
self.interfaceOrientation
, does your code work?这是我在 swift for i:
viewWillTransitionToSize:withTransitionCoordinator: 方法中的代码,用于确定您是旋转到纵向还是横向。
当检测到纵向模式时,我的代码基本上将方向更改回横向模式。
Here is my code in swift for i:
viewWillTransitionToSize:withTransitionCoordinator: method above to figure out whether you are rotating to portrait or landscape.
my code basically changes the orientation back to landscape mode when portrait mode is detected.
使用:
Use: