简体   繁体   English

iPhone强行旋转

[英]iPhone force rotation

I have been reading a ton on rotation, but not finding a solution to my query. 我一直在阅读旋转,但没有找到我的查询的解决方案。 Here goes: 开始:

I have a portrait application with a tabbar and hidden navigation controller in my tab. 我有一个肖像应用程序,在我的选项卡中有一个标签栏和隐藏的导航控制器。 At a point in the app, the next view must be landscape. 在应用程序中的某个点上,下一个视图必须是横向视图。

The XIB layout has been done in landscape, so I want to bring up the xib without any translation or pixel moving code. XIB布局是在横向上完成的,所以我想调出xib而不需要任何平移或像素移动代码。 (not thinking this is required) I have tried just pushing the view (remains in portrait), shifting the view using various methods (non seem to line thing up properly). (不认为这是必需的)我试过只是推动视图(保持纵向),使用各种方法移动视图(似乎没有正确排队)。

Is there a way to tell the view that it is already laid out for landscape prior to it being opened? 有没有办法告诉观点它在开放前已经为景观布局了?

Thanks in advance! 提前致谢!

Found it, this code does the trick in the viewdidload: 找到它,这段代码完成了viewdidload中的技巧:

self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);

Still have 1 odd thing. 还有一件奇怪的事情。 No matter what I do to set the navigation bar to hidden, it does not rotate, and stays at the left side of the view. 无论我如何将导航栏设置为隐藏,它都不会旋转,并保持在视图的左侧。

[[self navigationController] setNavigationBarHidden:YES animated:NO];

Has anyone seed this behavior and solved? 有没有人种下这种行为并解决了?

I'm positive that you cannot 'force' a rotation. 我很肯定你不能“强迫”轮换。 The system decides when to change the orientation of the device; 系统决定何时改变设备的方向; so the 'orientation' properties are essentially read-only. 所以'orientation'属性基本上是只读的。 I looked into this same problem a long time ago when I wanted to make sure a particular view always displayed in one orientation. 很久以前,当我想确保特定视图始终以一个方向显示时,我调查了同样的问题。

Due to this, most apps allow all of their views and view controllers to work in any of the orientations the app supports. 因此,大多数应用程序允许其所有视图和视图控制器在应用程序支持的任何方向上工作。 I've found that trying to restrict the behavior of some views and view controllers ultimately creates more hassle, and can cause issues when transitioning between views and view controllers. 我发现尝试限制某些视图和视图控制器的行为最终会产生更多麻烦,并且在视图和视图控制器之间转换时可能会导致问题。

The code you posted will work for your view. 您发布的代码适用于您的视图。 You are not actually changing the orientation at all; 你根本没有改变方向; your view is just behaving like it has been rotated by drawing in a rotated fashion. 您的视图就像通过以旋转方式绘制而旋转一样。 I'm not sure if you can do the same thing to the navigation bar or not, but it's worth a shot. 我不确定你是否可以对导航栏做同样的事情,但它值得一试。 If you are able to control the view properties of the navigation bar (it is a UIView as well), applying the same pattern you are using for your custom view should work. 如果您能够控制导航栏的视图属性(它也是UIView),则应用您用于自定义视图的相同模式应该有效。

Most apps that want a view to only be in landscape ultimately force their entire app to be in landscape. 大多数希望视图仅在横向视图中的应用程序最终会强制整个应用程序处于横向状态。 For instance, Flight Control only supports one orientation. 例如,Flight Control仅支持一个方向。 Thus, the drawing code is pretty simple; 因此,绘图代码非常简单; regardless of orientation, just draw the view and rotate it to the one orientation it supports (either landscape left or right). 无论方向如何,只需绘制视图并将其旋转到它支持的一个方向(向左或向右横向)。

Your app's design wouldn't be that easy... it sounds like you are not designing a full-screen app. 你的应用程序的设计并不那么容易......听起来你并没有设计一个全屏应用程序。 You would have to worry about the navigation bar and status bar being properly drawn. 您将不得不担心正确绘制导航栏和状态栏。

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

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