我已经将第三方库导入到我的项目中,我在我的原始项目的appDelegate中将其称为主ViewController。我试图添加一个backButton(不更改第三方库的代码)。
我将在AppDelegate中展示以下内容的VC
ABSViewController *abs = [[ABViewController alloc] init];
[self.window.rootViewController presentViewController:abs
animated:NO
completion:nil];
然后,我尝试通过以下方式以编程方式添加我的UIButton,但即使调用“bringSubViewToFront”,它也不会出现在最前面
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
backButton.layer.backgroundColor = [UIColor blueColor].CGColor;
[abs.view addSubview:backButton];
[abs.view bringSubviewToFront:backButton];
我可以看到按钮是在presentViewController动画完成之前创建的,但是它位于ABSViewController(库ViewController)的后面
最佳答案
我认为您需要在presentViewController
的完成处理程序中添加按钮
ABSViewController *abs = [[ABViewController alloc] init];
[self presentViewController:viewController animated:YES completion:^{
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
backButton.layer.backgroundColor = [UIColor blueColor].CGColor;
[abs.view addSubview:backButton];
[abs.view bringSubviewToFront:backButton];
}];
关于ios - 在新库ViewController上方添加UIButton,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30477976/