简体   繁体   English

处理iPhone设备旋转时的横向显示

[英]Handling landscape display on iphone device rotation

I'm working on an iphone app with tab bars each one associated to a navigation controller. 我正在使用一个iphone应用程序,其中每个选项卡栏都与导航控制器相关联。 In one of these controllers I've a Table View showing some listing and when a row is selected another view displays specific informations and a button to see some related photos. 在这些控制器中的一个中,我有一个显示一些列表的表格视图,当选择了一行时,另一个视图显示特定信息和一个用于查看一些相关照片的按钮。

I'm having an issue displaying the photo view in landscape. 我在横向显示照片视图时遇到问题。

The photo view controller contains a UIImageView to display one photo at a time and this ImageView object size is 320x460 showing in full screen mode. 照片视图控制器包含一个UIImageView,可一次显示一张照片,并且此ImageView对象的大小为320x460,以全屏模式显示。 To handle rotation I've added the following code: 为了处理旋转,我添加了以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

But it's not rotating and iphone simulator status bar is still in the portrait position, so not rotated too. 但是它没有旋转,并且iphone模拟器状态栏仍处于纵向位置,因此也没有旋转。

I've also changed the method like this: 我也改变了这样的方法:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return YES;
}

Still no changes on device rotation. 设备旋转仍然没有变化。 And the options in Project->Summary(Tab)->Supported Device Orientation->Desired Orientations clearly enable landscape mode (right/left). 并且Project-> Summary(Tab)-> Supported Device Orientation-> Desired Orientation中的选项清楚地启用了横向模式(右/左)。

Can you help me understand what I may be missing ? 你能帮助我了解我可能会想念的东西吗?

Thx for helping, 感谢您的帮助,

Stephane 斯特凡

With a tab bar controller, it will only rotate if your view controllers for all your tabs allow the orientation. 使用标签栏控制器时,只有当所有标签的视图控制器允许方向时,它才会旋转。 Kind of annoying, but there it is. 有点烦人,但确实如此。 You need to override shouldAutorotateToInterfaceOrientation in all your other view controllers too, and they need to be able to smoothly adjust to those orientations. 您还需要在所有其他视图控制器中覆盖shouldAutorotateToInterfaceOrientation,并且它们必须能够平滑地适应这些方向。

If it's not practical to support landscape orientations on the other view controllers, maybe you could try some hacking, for example by subclassing UITabBarController and overriding its shouldAutorotateToInterfaceOrientation to instead return YES if the current view controller returns YES. 如果在其他视图控制器上支持横向方向不可行,则可以尝试进行一些黑客入侵,例如,通过子类化UITabBarController并重写其shouldAutorotateToInterfaceOrientation,以在当前视图控制器返回YES时返回YES。 But that might get your app rejected as not conforming to Human Interface Guidelines, since you are trying to circumvent standard interface behavior. 但这可能会导致您的应用不符合人机界面准则而被拒绝,因为您正试图规避标准界面行为。

Check if you're not in some sort of a subclassed container view controller (like your own UINavigationController or UITabBarController subclasses). 检查您是否不在某种子类化的容器视图控制器中(例如您自己的UINavigationController或UITabBarController子类)。 If that's the case make sure it does not override shouldAutorotateToInterfaceOrientation: method. 如果是这种情况,请确保它不会覆盖shouldAutorotateToInterfaceOrientation:方法。

Your looking in the wrong place: in your RootViewController.m file look for the following code: 您在错误的位置查找:在RootViewController.m文件中查找以下代码:

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
//lots of useless comments
//
return (UIInterfaceOrientationIsPortrait(interfaceOrientation) ); //THIS LINE HERE
// return (UIInterfaceOrientationIsLandScape(interfaceOrientation) ); 

the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. 表示return(UIInterface ... Portrait)的行是确定应用程序旋转能力的行。 You can change this to whatever to allow you to be able to rotate completely, keep it at a certain orientation, or whatever you desire... 您可以将其更改为任何值,以使其能够完全旋转,保持一定方向或任何您想要的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM