我创建了一个 subview ,用作 iOS 应用程序中的 HUD。该应用支持纵向和横向显示方向。
即使模式是横向, subview 有时也会以纵向模式出现。 subview 由这些行添加:
self.infoHUDViewController = [[[InfoHUDViewController alloc] initWithNibName:@"InfoHUD" bundle:nil] autorelease];
[self.view addSubview:self.infoHUDViewController.view];
所以如果在 viewDidLoad
方法中添加 subview ,效果会很好。但是,如果在响应按钮按下的 IBAction
方法中添加 View ,则它在横向模式下不起作用。 subview 显示为纵向模式(旋转 90°,仅填充半个屏幕宽度,并超出屏幕边界)。
真正奇怪的是:在 subview 的 View Controller 的初始化方法中,显示方向被正确设置为横向。我在这里遗漏了什么吗?
最佳答案
我找到了解决这个问题的办法。
我加了
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
self.view.frame = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
} else {
self.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
}
到 viewDidLoad
方法。现在,在所有情况下一切正常。
关于ios - subview 的方向不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7900032/