简体   繁体   中英

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. Everything worked fine, until I deleted the scene in the IB editor and tried to remake it. I changed no code at all, but now, whenever I run my app in the iOS Simulator, I see this:

在此处输入图片说明

Whereas previously I'd see a horizontal iPad screen with the status bar at the top and my grid filling the screen.

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.

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. The same thing happens: a weird sideways 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.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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