【发布时间】:2012-09-05 17:14:37
【问题描述】:
我正在尝试在我的一个项目中使用 UIViewController 包含功能。该应用程序只能在横向模式下使用。
我将 UIViewController A 添加为 UIViewController B 的子视图,并将 A 的主视图添加为 之一的子视图B 的意见。我还在 B 中保存了对 A 的引用:
@interface BViewController : UIViewController
@property (retain, nonatomic) AViewController *aVC;
@end
@implementation BViewController : UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.aVC = [self.storyBoard instantiateViewControllerWithIdentifier:@"A"];
[self addChildViewController:self.aVC];
[self.myContainerView addSubview:self.aVC.view];
}
@end
我遇到的问题是横向方向没有得到尊重。我进行了一些调试并找到了解决方案,但我担心它并不理想,因为它更像是一种 hack:
在 B 中:
- (void)viewDidLoad
{
[super viewDidLoad];
self.aVC = [self.storyBoard instantiateViewControllerWithIdentifier:@"A"];
[self addChildViewController:self.aVC];
[self.myContainerView addSubview:self.aVC.view];
[self.aVC didMoveToParentViewController:self];
}
在 A 中:
- (void)didMoveToParentViewController:(UIViewController *)parentVC
{
// Interchange width and height
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.**height**, self.view.frame.size.**width**);
}
我错过了什么吗?
【问题讨论】:
标签: ios cocoa-touch ios5 uiviewcontroller