UIViewController加载旋转为横向,但仅支持纵向 [英] UIViewController loads rotated to landscape but only supports portrait

查看:169
本文介绍了UIViewController加载旋转为横向,但仅支持纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以以纵向方向加载仅纵向视图控制器,即使父视图控制器(和电话)处于横向方向?

Is there a way to load a portrait only view controller in portrait orientation even though the parent view controller (and phone) is in landscape orientation?

此特定的UIViewController仅适合于纵向模式(这是一个颜色选择器),因此shouldAutorotateToInterfaceOrientation:中的代码仅对纵向方向返回YES.如果在已加载视图的情况下转动手机,它会保持纵向,则效果很好,但是在加载视图的NIB时,如果手机已经在横向,则无济于事.

This particular UIViewController only fits in Portrait mode (it's a color picker), so the code in shouldAutorotateToInterfaceOrientation: returns YES only for portrait orientations. That works fine if you turn the phone while the view is already loaded, it stays in portrait, but it doesn't help if the phone is already in landscape when the view's NIB is loaded.

加载ViewController时,如果屏幕已经处于横向,则该视图为纵向布局,并且该视图的下半部分被切除.我尝试提出景观布局,但是分段控制是个问题.

When the screen is already in landscape orientation when the ViewController is loaded, the view is in portrait layout and the bottom half of the view is cutoff. I tried coming up with a landscape layout but the segmented control is a problem.

编辑-我曾尝试在viewWillAppear中使用setStatusBarOrientation,但它只会影响状态栏,导航栏和视图仍会针​​对风景旋转.

EDIT - I've tried using setStatusBarOrientation in viewWillAppear but it only affects the status bar, the navigation bar and view are still rotated for landscape.

在iPhone上的3.1.3和4.0中会发生这种情况.

This happens with 3.1.3 and 4.0 on the iPhone.

推荐答案

如果适用于您的应用,则可以考虑使用模式视图控制器. IIRC提供的模态视图控制器确实可以正确旋转.

If it works for your app, you could consider using a modal view controller instead. IIRC presenting a modal view controller does handle rotating properly.

这篇关于UIViewController加载旋转为横向,但仅支持纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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