我有一个支持方向更改的iPad应用程序的嵌套视图层次结构。它看起来类似于下面的代码。
UIViewController
UIView
- UIView
- UIImageView (disable rotation)
- UIImageView
- UIView (disable rotation)
- UIView
- UIView
...我想锁定我的一些子视图的方向,同时允许其他子视图自动旋转和调整大小。我似乎不太明白如何做到这一点。
一种方法似乎是在willAnimateRotationToInterfaceOrientation:中手动轮转子视图。这并不是特别吸引人,因为SDK正在执行一次循环,而我只是想撤销它。
有没有一种方法可以简单地禁用子视图的方向更改,或者其他一些方法来重构我的层次结构?
发布于 2013-01-19 06:16:11
这是另一种方法。只需将以下代码放入您的viewController viewDidLoad:
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.https://stackoverflow.com/questions/7353789
复制相似问题