iPhone旋转问题
我花了很多令人沮丧的时间试图在 iPhone 版本的 Tunepal 上进行轮换。
首先,我有一个选项卡栏控制器,其中有一个导航控制器控制每个视图。
实际上,我只希望我的视图之一能够旋转,那就是 TuneDisplay
。
我有一个 UITabBarController
的子类并覆盖了 shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
if (self.selectedViewController != nil)
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
else
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
在每个选项卡的每个视图控制器中,我都覆盖了该方法并为我想要的每个方向返回 YES支持。一切都很好,一切都按其应有的方式进行。如果我尝试在不支持旋转的选项卡上进行旋转,则不会发生任何情况。
如果我从旋转的选项卡移至不支持该旋转的选项卡,就会出现问题。新选项卡也会旋转显示!所有这些的屏幕截图都包含在这里:
http://tunepal.wordpress.com /2010/04/20/rotation-woes/
有什么方法可以让它在点击选项卡时旋转回纵向吗?
我尝试过不受支持的 setOrientation
技巧,但首先它无法正常工作,其次我收到了 Apple 的警告,因为我将其包含在我的上一个版本中。
如果(正如我怀疑的那样)没有办法限制这种行为:
当我旋转设备时如何使麦克风图像缩放?
如何使按钮和进度条展开以适应工具栏的宽度?
此外,其中一个可以正常旋转的选项卡有一个表格,带有搜索栏。第一次向右或向左旋转时,搜索栏右侧出现一个黑条。如果我随后向后旋转并再次旋转,该条就会消失!我已经在界面生成器的搜索栏上启用了 struts 和 springs 功能,看起来它应该表现正常。
关于如何解决这个问题有什么想法吗?
非常感谢
布莱恩的想法和反馈
I have been spending many frustrating hours trying to get rotations working on the iPhone version of Tunepal.
Firstly, I have a tab bar controller, with a navigation controller controlling each of the views.
I actually only want one of my views to be able to rotate and that is the TuneDisplay
.
I have a subclassed the UITabBarController
and overridden the shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
if (self.selectedViewController != nil)
{
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
else
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
}
In each of the view controllers for each of the tabs I have overridden the method and returned YES for each orientation I want to support. All well and good and everything works as it should. If I try and do a rotation on a tab that doesn’t support the rotation, nothing happens.
The problem occurs if I move from a tab thats rotated to a tab that isnt supposed to support that rotation. The new tab is displayed rotated too! Screenshots for all this are included here:
http://tunepal.wordpress.com/2010/04/20/rotation-woes/
Is there any way I can make it rotate back to portrait on tapping the tab?
I have tried the unsupported setOrientation
trick, but firstly it doesnt work correctly and secondly I received a warning from Apple for including it in my last build.
If (as I suspect) there is no way to limit this behavior:
How do I make the microphone image scale when I rotate the device?
How do I make the buttons and the progress bar expand to fit the witdh of the toolbar?
Also, one of the tabs that rotates ok has a table, with a search bar. The first time I rotate to the right or to the left, I get a black bar to the right of the search bar. If I subsequently rotate back and rotate again, the bar disappears! I have enabled the struts and springs things on the search bar in the interface builder and it looks like it should behave correctly.
Any ideas about how to fix this?
Ideas, feedback much appreciated
Bryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是完整的答案。旋转严重不一致。你已经做了正确的事情。有几个方面在模拟器中不起作用,因此您需要在设备上确认所有测试。在较旧的操作系统版本中,表格标题和搜索栏不会调整为全宽,因此请坚持使用 3.1.3 或更高版本。
最常见的问题:
shouldAutorotateToInterfaceOrientation:
返回YES
;您可能需要打开方向通知才能从设备中获取更多有用的信息:
完成后记得将其关闭并从通知中删除;这应该有很高的开销。
设置要调整图像大小的视图
contentMode
属性;与您在 IB 中设置的autoresizingMask
一起使用,应该没问题。另请记住,您可以使用两种不同的笔尖来实现纵向和横向模式。有一个示例项目可以执行此操作(“
WhichWayIsUp
”);另请参阅视图控制器编程指南(“创建备用景观界面”)。如果调用旋转方法,则 UI 应一致旋转。您会发现它们并不总是在应该被调用的时候被调用。
在视图上调用旋转变换来强制旋转并不难。不应该需要它,但有时这是它们旋转的唯一方式。
如果您弄清楚了,请告诉我们。
This isn't a full answer. Rotation is seriously inconsistent. You have done the right things. Several aspects don't work in the simulator, so you need to confirm all your testing on a device. Table headers and search bars don't resize to full width in older OS versions, so stick with 3.1.3 or higher.
Commonest problems:
shouldAutorotateToInterfaceOrientation:
to returnYES
;You may need to turn on orientation notifications to get more useful information out of the device:
Remember to turn it off and remove yourself from the notifications when you are done; this is supposed to have a high overhead.
Set the view
contentMode
property for your image to resize; together withautoresizingMask
, which you are setting in IB, you should be OK.Remember also that you can use two different nibs for portrait and landscape modes. There is an example project that sort of does this ("
WhichWayIsUp
"); see the View Controller Programming Guide also ("Creating an Alternate Landscape Interface").If the rotation methods are being called, then the UI should be rotated consistently. You will find that they aren't always called when they should be.
It isn't hard to call a rotational transform on your views to force a rotation. It shouldn't be needed, but sometimes that's the only way they will rotate.
If you get it figured out, let us know.
听起来您在显示选项卡时正在正确处理旋转。然而,如您所知,没有快速的方法来切换轮换。您需要做的是使用 CGAffineTransform 自行旋转视图。请参阅此问题: 是否有记录的方法来设置iPhone 方向?
要缩放图像,您应该能够单击 Interface Builder 中包含图像的 UIImageView 内的箭头。右上角有一个小箭头,您可以单击以查看视图旋转时的行为,以确保其正确缩放。但您可能最好不要像链接问题的答案那样缩放图像并进行旋转。
It sounds like you are handling the rotation correctly while the tab is displayed. However, as you know, there's no quick way to switch rotations. What you will have to do is rotate the view yourself using CGAffineTransform. See this question: Is there a documented way to set the iPhone orientation?
To scale the image, you should be able to click the arrows inside the UIImageView housing the image in Interface Builder. There's a little arrow in the upper right hand corner you can click to see how the view behaves when it's rotated to make sure it scales correctly. But you'd probably be better off not scaling the image and hadling the rotation as in the answer to the linked question.