我想在我的項目之一中使用UIViewController遏制功能。該應用僅用於橫向模式。UIViewController遏制
我添加的UIViewController 甲作爲UIViewController中乙的子並添加甲的主視圖爲乙一個的子視圖的視圖。我也在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
我遇到的問題是橫向不受尊重。我做了一些調試,並找到了解決辦法,但我擔心的是不理想的,因爲它更像是一個黑客:
在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];
}
在答:
- (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**);
}
我缺少的東西這裏?
+1鏈接到您的書,非常徹底 –