我不确定是什么触发了您的视图更改,因此您必须编写该代码。
家长
@implementation ParentViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.vcOne = [[OneViewController alloc] init];
[self addChildViewController:self.vcOne];
[self.view addSubView:self.vcOne.view];
self.vcTwo = [[TwoViewController alloc] init];
}
-(void)switchViews {
//logic to animate in view that isn't present
}
@end
查看控制器一
@interface OneViewController ()
@property(strong, nonatomic) UIView *vOne;
@end
@implementation OneViewController
-(UIView*)vOne {
if(_vOne == nil) {
_vOne = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
}
return _vOne;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubView:self.vOne];
}
@end
视图控制器二
@interface TwoViewController ()
@property(strong, nonatomic) UIView *vTwo;
@end
@implementation TwoViewController
-(UIView*)vTwo {
if(_vTwo == nil) {
_vTwo = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
}
return _vTwo;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addSubView:self.vTwo];
}
@end