首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS:禁用子视图的自动旋转

iOS:禁用子视图的自动旋转
EN

Stack Overflow用户
提问于 2011-09-09 04:03:40
回答 2查看 28.4K关注 0票数 19

我有一个支持方向更改的iPad应用程序的嵌套视图层次结构。它看起来类似于下面的代码。

代码语言:javascript
复制
UIViewController
    UIView
        - UIView
            - UIImageView (disable rotation)
            - UIImageView
            - UIView (disable rotation)
        - UIView
        - UIView
        ...

我想锁定我的一些子视图的方向,同时允许其他子视图自动旋转和调整大小。我似乎不太明白如何做到这一点。

一种方法似乎是在willAnimateRotationToInterfaceOrientation:中手动轮转子视图。这并不是特别吸引人,因为SDK正在执行一次循环,而我只是想撤销它。

有没有一种方法可以简单地禁用子视图的方向更改,或者其他一些方法来重构我的层次结构?

EN

Stack Overflow用户

发布于 2013-01-19 06:16:11

这是另一种方法。只需将以下代码放入您的viewController viewDidLoad:

代码语言:javascript
复制
    YourAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
        // the view you don't want rotated (there could be a heierarchy of views here):
    UIView *nonRotatingView = [[UIView alloc] initWithFrame:CGRectMake(100,0,30,500)];
    nonRotatingView.backgroundColor = [UIColor purpleColor];

        // make sure self.view and its children are transparent so you can see through to this view that will not be rotated behind self.view.

    [delegate.window insertSubview:nonRotatingView  belowSubview:self.view];

        // you can't put it in the front using:
        //    [delegate.window insertSubview:nonRotatingView aboveSubview:self.view];
        // It will show up the same as before

    // you should declare nonRotatingView as a property so you can easily access it for removal, etc.
票数 10
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7353789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档