Ios addChildViewController在横向运行时不工作
我正在使用容器视图控制器在3秒后将子视图添加到当前视图控制器:Ios addChildViewController在横向运行时不工作,ios,objective-c,ios7,Ios,Objective C,Ios7,我正在使用容器视图控制器在3秒后将子视图添加到当前视图控制器: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor greenColor]; [self performSelector:@selector(open
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor greenColor];
[self performSelector:@selector(open) withObject:nil afterDelay:3.0];
}
-(void)open{
ViewController2 *test = [[ViewController2 alloc] init];
test.view.backgroundColor = [UIColor redColor];
[self addChildViewController:test];
[self.view addSubview:test.view];
}
ViewController2是一个简单的视图,在init上只有以下内容:
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
事情是这样的,如果我在纵向视图中打开第二个视图,然后旋转到横向视图,屏幕上将充满红色,但是如果我从横向视图中打开第二个视图,则会发生以下情况:
有什么线索吗?只需设置框架即可。打开时的视图界面采用投影视图的大小
-(void)open{
ViewController2 *test = [[ViewController2 alloc] init];
test.view.backgroundColor = [UIColor redColor];
test.view.frame = self.view.bounds;
[self addChildViewController:test];
[self.view addSubview:test.view];
}
建议:开始学习自动布局 这里有一个解决方案
-(无效)打开{
测试=[self.storyboard实例化eviewcontrollerwhiteIdentifier:@“ViewController2”];
test.view.backgroundColor=[UIColor redColor];
test.view.frame=self.view.bounds;
[自添加ChildViewController:测试];
[self.view addSubview:test.view];
}