设备旋转 iPhone
我所有的宽度、高度、位置和所有内容都是相对于视图等设置的,因此如果 iPhone 旋转,它应该像以前一样“扩展以适应”。 :)
我该如何告诉 iPhone 处于“横向模式”,即:刷新,但现在所有宽度都是高度,所有高度都是宽度?
谢谢 汤姆
编辑 这是我目前拥有的代码...它仍然不起作用 - 我似乎无法弄清楚如何使其工作
在我的视图控制器(不是根视图控制器)中我有这个方法:(
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
我也有尝试将此方法放入我的 root 视图控制器中,但这也不起作用)
然后在我的 viewDidLoad
方法中我有这个:
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[self.view setAutoresizesSubviews:YES];
这不起作用。 :( 至少在模拟器中不是。
All of my widths, heights, positions and everything are set relative to views and such, so if the iphone is rotated it should "expand to fit" as it were. :)
How would I go about telling the iphone to be in "landscape mode" ie: refresh, but now all widths are heights and all heights are widths?
Thanks
Tom
EDIT
Here is the code I currently have... it still doesn't work - I can't seem to figure out how to make it work
In my view controller (not the root view controller) I have this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
(i have also tried putting this method into my root view controller, but that didn't work either)
Then in my viewDidLoad
method I have this:
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[self.view setAutoresizesSubviews:YES];
This doesn't work. :( at least not in the simulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您的期望设置视图的 AutoresizingMask 。
或实现
layoutSubViews
方法。另外,不要忘记实现 viewController 的
shouldAutorotateToInterfaceOrientation
方法。流程如下。shouldAutoRotateToInterfaceOrientation
事件willRotateToInterfaceOrientation
事件将发送到控制器,autoresizingMask
调整其视图大小code>autoresizesSubviews
属性为 true,则深入到子视图的过程didRotateToInterfaceOrientation
事件将发送到控制器。这是一个示例 viewController 代码
Set the
AutoresizingMask
of your view according to what you expect.or implement the
layoutSubViews
method.Also, don't forget to implement the
shouldAutorotateToInterfaceOrientation
method of the viewControllers. The flow is as follow.shouldAutoRotateToInterfaceOrientation
eventwillRotateToInterfaceOrientation
event is send to the controllersautoresizingMask
autoresizesSubviews
property is true, the process drill down to the subviewsdidRotateToInterfaceOrientation
event is sent to the controller.Here is a sample viewController code
您可以通过设置自动调整视图的大小:
因此,当您旋转时,它会自行调整大小。
但我认为它不会满足你的需要。
因此,也许您应该添加一个在设备旋转时调用的函数(在控制器中):
然后在刷新布局中您可以根据需要更改自己的宽度/高度。
祝你好运 !
You can adjust the size of your view automatically by setting :
So when you rotate it will resize itself.
But I think it won't do what you need.
So maybe you should add a function (in controller) which is called when device rotate :
Then in refreshLayouts you change yourself the width/height like you want.
Good Luck !
首先检查视图控制器的旋转事件回调方法是否被调用:
如果这些方法没有被调用,那么就没有必要继续下去,因为你的 viewController 根本没有旋转!
这让我感兴趣 - “在我的视图控制器中(不是根视图控制器)”。如何将视图控制器添加到窗口层次结构中?您是要呈现它,还是只是将其视图作为子视图添加到根视图控制器?
First check if your view controller's call back methods for rotation events are being called or not:
If these are not called, then there is no point in going further because your viewController is not rotated at all!
This interests me - "In my view controller (not the root view controller)". How are you adding your view controller to the window hierarchy? Are you presenting it, or just adding its view as a sub-view to, say a root view controller?