禁用单个UIView的自动旋转 [英] Disabling autorotate for a single UIView

查看:113
本文介绍了禁用单个UIView的自动旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这似乎应该比较简单,但我已经在一个小时的谷歌搜索,似乎找不到我需要的。

Okay, this seems like it should be relatively simple, but I've been Googling for the better part of an hour, and can't seem to find what I need.

我有一个视图控制器有几个不同的部分:背景视图,标题视图和几个按钮。现在,我想让标题和按钮正确自动旋转(他们做,当我从shouldAutorotateToInterfaceOrientation :)返回YES,但在任何情况下都不应该背景视图旋转。是否有正确的方法来做到这一点?

I have a view controller that has a few different parts: a background view, a header view, and a few buttons. Now, I want the header and buttons to autorotate properly (they do, when I return YES from shouldAutorotateToInterfaceOrientation:), but under no circumstances should the background view rotate. Is there a proper way to do this?

推荐答案

如果你不想暂时旋转背景视图,更改为具有正确的方向,则需要关闭视图的自动旋转。没有两种方法。

If you don't want temporary rotations of the background view after which the background is changed to have the correct orientation, you'll need to turn off Autorotation for the View. No two ways about it.

您需要自己处理按钮的旋转。你可以做一个不错的布局,或者把它们放在例如一个ScrollView,只是调整大小。

You would need to handle the rotation of the buttons yourself. You can either make a nice layout or put them on for example a Scrollview and just resize that.

无论如何,你需要添加一个观察者自己旋转它,

Either way, you'd need to add an observer to rotate it yourself,

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];

在didRotate中,你可以调整大小, >

And in didRotate you do the resize, with a nice animated transition, if you like.

- (void) didRotate:(NSNotification *)notification {
 int ori=1;
    UIDeviceOrientation currOri = [[UIDevice currentDevice] orientation];
    if ((currOri == UIDeviceOrientationLandscapeLeft) || (currOri == UIDeviceOrientationLandscapeRight)) ori=0;
}

希望对你排序。如果导航栏或状态栏导致视图收藏在顶部栏下,有办法修复。

Hope that sorts you. If Navigation bars or status bars cause the View to get tucked in under the top bar, there are ways to fix that.

这篇关于禁用单个UIView的自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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