我有三个按键和一个UIView
(我称之为containerView
),点击每个按钮时,containerView
将显示通过自定义赛格瑞在UIViewController
视图,按钮使用一个IBAction
方法(switchView
),我把这三个按钮放在一个叫做navButtons
的IBOutletCollection
; 和viewDidLoad
我打电话switchView
使containerView
显示第一个视图控制器。IOS定制Segue公司和ContainerView
代码运行良好,没有错误,唯一的问题是当我点击第一个按钮时,第一个UIViewController
将显示在containerView
,UIImageView(按钮,标签等)应该在屏幕的中心,但它在第一次加载时从不像这样,当我点击另一个按钮时,再次点击第一个按钮,它的行为如预期, 我不知道发生了什么,第一次加载和再次点击它们之间的区别是什么。 是否有任何我在代码中遗漏?
我不擅长英语,对不起有什么不清楚的。
- (void)viewDidLoad {
[super viewDidLoad];
self.availableIdentifier = [[NSMutableArray alloc] initWithObjects:@"Seg1",@"Seg2",@"Seg3", nil];
[self switchView:self.navButtons[0]];
}
- (IBAction)switchView:(UIButton *)sender
{
[self setSelectedIndexs:(int)sender.tag];
}
- (void)setSelectedIndexs:(int)index
{
[self performSegueWithIdentifier:self.availableIdentifier[index] sender:self.navButtons[index]];
}
//Code of Custom Segue:
-(void)perform
{
ViewController *controller = (ViewController *)self.sourceViewController;
UIViewController *destController = (UIViewController *)self.destinationViewController;
for (UIView *view in controller.containerView.subviews)
{
[view removeFromSuperview];
}
controller.currentController = destController;
[controller.containerView addSubview:destController.view];
[controller.containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
[destController didMoveToParentViewController:controller];
}
是的,这是重点,需要多做一点:将destController.view.frame的y设置为0;感谢你的回答; –