如何在 iPhone 应用程序上仅支持纵向模式 [英] How to support only portrait mode on an iPhone app

查看:29
本文介绍了如何在 iPhone 应用程序上仅支持纵向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的 iPhone 应用程序中遇到一个奇怪的问题.我希望我的应用支持纵向模式,但由于某种原因我不能这样做(设备和模拟器).

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:

  • 在 Xcode 的 TARGET summary 部分,我只选择了肖像.
  • 我所有的 ViewController 都实现了 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?

这是我如何实现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."

什么意思?

推荐答案

屏幕上可以有多个 ViewController.UITabBarController 本身就是一个 UIViewController,它只会将 shouldAutorotateToInterfaceOrientation: 请求传递给它选择的视图控制器.默认实现会这样做,但如果您将其子类化,XCode 生成的代码(从 iOS 5.1 开始)不会.

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.

这篇关于如何在 iPhone 应用程序上仅支持纵向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆