【发布时间】:2011-05-13 17:29:29
【问题描述】:
我有一个 UIView 作为纵向模式下的 XIB。
这个视图以编程方式添加到视图控制器中,如下所示:
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"InputView" owner:self options:nil];
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
此视图已正确设置自动调整大小的蒙版,并且在方向从纵向变为横向时可以正常旋转。
但是,如果方向是已经横向并且我在方向更改之后创建视图,则它具有初始纵向方向。
有没有办法通过使用它的掩码告诉视图初始化或调整自身大小为纵向?
提前感谢您的回复!
编辑: 使用 oculus 和 Inder Kumar Rathore 的建议(谢谢大家!),我将代码更改为:
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
[self.view setNeedsLayout];
[self.view layoutSubviews];
[self.view layoutIfNeeded];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[self shouldAutorotateToInterfaceOrientation:orientation];
不幸的是,根本没有任何变化。 我想我发现有人问同样的问题:
When adding a sub view the view does not resize if the app is in landscape mode
答案正确地识别了问题,但不是很鼓舞人心... 当然,我可以创建两个笔尖或调整框架的大小,但这似乎与自动调整大小的想法背道而驰。 我很难相信在唤醒后没有办法告诉笔尖并将其添加到视图中以使用其自动调整大小功能......当设备旋转时,它可以完美地工作。
编辑 2:
idz的解决办法:
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
inputView.frame = self.view.bounds;
[inputView show];
谢谢!
【问题讨论】:
-
我遇到了这个问题,有两个皱纹:(1)我使用的是受控视图,笔尖加载了 UIVC; & (2) 它只出现在 iOS 4.3 下,而不是 5.0。 yasirmturk 的方法为我修复了它。
标签: iphone orientation addsubview autoresizingmask