处理 iPhone 设备旋转上的横向显示
我正在开发一款带有标签栏的 iPhone 应用程序,每个标签栏都与一个导航控制器相关联。在其中一个控制器中,我有一个显示一些列表的表视图,当选择一行时,另一个视图会显示特定信息和一个用于查看一些相关照片的按钮。
我在横向显示照片视图时遇到问题。
照片视图控制器包含一个 UIImageView 来一次显示一张照片,该 ImageView 对象大小为 320x460,以全屏模式显示。为了处理旋转,我添加了以下代码:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
但它没有旋转,并且 iphone 模拟器状态栏仍然处于纵向位置,因此也没有旋转。
我还改变了这样的方法:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
设备旋转仍然没有变化。并且项目->摘要(选项卡)->支持的设备方向->所需方向中的选项明确启用了横向模式(右/左)。
你能帮我理解我可能缺少什么吗?
感谢您的帮助,
斯蒂芬
I'm working on an iphone app with tab bars each one associated to a navigation controller. 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. 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.
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).
Can you help me understand what I may be missing ?
Thx for helping,
Stephane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于标签栏控制器,只有当您的所有选项卡的视图控制器允许方向时,它才会旋转。有点烦人,但就是这样。您还需要在所有其他视图控制器中重写 shouldAutorotateToInterfaceOrientation,并且它们需要能够平滑地调整到这些方向。
如果在其他视图控制器上支持横向方向不切实际,也许您可以尝试一些黑客攻击,例如通过子类化 UITabBarController 并覆盖其 shouldAutorotateToInterfaceOrientation ,以在当前视图控制器返回 YES 时返回 YES。但这可能会导致您的应用程序因不符合人机界面指南而被拒绝,因为您试图规避标准界面行为。
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.
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. But that might get your app rejected as not conforming to Human Interface Guidelines, since you are trying to circumvent standard interface behavior.
检查您是否不在某种子类容器视图控制器中(例如您自己的 UINavigationController 或 UITabBarController 子类)。如果是这种情况,请确保它不会覆盖 shouldAutorotateToInterfaceOrientation: 方法。
Check if you're not in some sort of a subclassed container view controller (like your own UINavigationController or UITabBarController subclasses). If that's the case make sure it does not override shouldAutorotateToInterfaceOrientation: method.
您找错了地方:在 RootViewController.m 文件中查找以下代码:
返回(UIInterface...Portrait)的行是确定应用程序旋转功能的行。您可以将其更改为任何内容,以使您能够完全旋转,将其保持在某个方向,或任何您想要的...
Your looking in the wrong place: in your RootViewController.m file look for the following code:
the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. 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...