How to support only portrait mode on an iPhone app

2019-06-24 14:42发布

I have a strange problem in an iPhone app I'm developing. I want my app to support ONLY portrait mode, but for some reason I can't do it (device & simulator).

To support only portrait mode I did as follow:

  • In the TARGET summary section on Xcode, I chose only portrait.
  • All my ViewControllers implements shouldAutorotateToInterfaceOrientation

But as I said it won't work, and the strange result is that the app support ALL the orientations (portrait, upside down, landscape left, landscape right).
Any ideas?

this how I implement shouldAutorotateToInterfaceOrientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     // Return YES for supported orientations
     NSLog(@"Checking orientation %d", interfaceOrientation);
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

I notice just now that when I rotate the phone I get this message:

"Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation."

What does it means?

4条回答
一纸荒年 Trace。
2楼-- · 2019-06-24 15:20

It is possible to have multiple ViewControllers on the screen. The UITabBarController is itself a UIViewController, and it only passes shouldAutorotateToInterfaceOrientation: requests to the viewControllers within if it chooses. The default implementation does this, but if you subclass it, the code XCode generates (as of iOS 5.1) does not.

查看更多
何必那么认真
3楼-- · 2019-06-24 15:26

On the Target Summary choose portrait only.

查看更多
Animai°情兽
4楼-- · 2019-06-24 15:39

Go to info.plist file. Right Click open it as source code. And look for this line. For me in iPad its like this:

  <key>UISupportedInterfaceOrientations~ipad</key>

Delete all other orientation and keep the only one which you need..Like this :

    <array>

    <string> UIInterfaceOrientationPortrait </string>

</array>
查看更多
Ridiculous、
5楼-- · 2019-06-24 15:44

check your plist and make sure the key there is set correctly.

查看更多
登录 后发表回答