简体   繁体   English

如何解决iOS模拟器的旋转问题?

[英]How can I fix iOS simulator rotation?

In my app I have set the storyboard to allow only horizontal and inverted horizontal rotations. 在我的应用中,我将情节提要板设置为仅允许水平和反向水平旋转。 I have a single view controller scene with a single UIView subclass in it. 我有一个视图控制器场景,其中有一个UIView子类。 Everything worked fine, until I deleted the scene in the IB editor and tried to remake it. 一切正常,直到我在IB编辑器中删除场景并尝试对其进行重新制作。 I changed no code at all, but now, whenever I run my app in the iOS Simulator, I see this: 我根本没有更改任何代码,但是现在,每当我在iOS Simulator中运行我的应用程序时,都会看到以下信息:

在此处输入图片说明

Whereas previously I'd see a horizontal iPad screen with the status bar at the top and my grid filling the screen. 以前,我会看到一个水平的iPad屏幕,顶部是状态栏,而我的网格则填充在屏幕上。

self.frame.size.width gives me 1024 and self.frame.size.height returns 748 in awakeFromNib , so my view thinks it has the right size and orientation. self.frame.size.width给我1024,而self.frame.size.heightawakeFromNib返回748,所以我认为它具有正确的大小和方向。

Thinking I'd made a mistake, I deleted the storyboard entirely and made a brand new one, again with a single view controller scene containing a single instance of my UIView subclass. 考虑到我犯了一个错误,我完全删除了情节提要,制作了一个全新的情节提要,再次使用一个包含我的UIView子类实例的单一视图控制器场景。 The same thing happens: a weird sideways iPad. 同样的事情发生了:一个奇怪的侧面iPad。

So, what have I done wrong? 那么,我做错了什么?

EDIT: A Bit more testing reveals that the view itself is also rotated. 编辑:更多测试显示该视图本身也在旋转。 In other words, the top left origin (0, 0) is actually in the bottom left of that picture above. 换句话说,左上角的原点(0,0)实际上在该图片的左下角。

Thanks! 谢谢!

Tim 提姆

Try setting the screen autorotation to: 尝试将屏幕自动旋转设置为:

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

You can delete this later if needed. 如果需要,您可以稍后删除它。 A similar instance as your happened to me. 与您发生在我身上的情况类似。 I changed no code, then Storyboard decided to change the orientation of my app. 我没有更改任何代码,因此Storyboard决定更改应用程序的方向。 Simply limiting the interface in the code fixed it in storyboard. 只需限制代码中的接口即可将其固定在情节提要中。 As I said, once fixed, you can delete the code if you don't need it. 如我所说,一旦修复,就可以删除不需要的代码。 Good luck! 祝好运!

It looks like you may just have your device rotated in the simulator. 看来您可能只是在模拟器中旋转了设备。 After you have hit the run button if you go to Hardware > Rotate Left it should fix your starting orientation and then it will start up in the correct orientation next time you run. 按下“ run按钮后,如果转到“ Hardware > Rotate Left它将固定您的起始方向,然后在下次运行时以正确的方向启动。

您是否在项目中将新创建的故事板设置为“开始故事板”?

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

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