我已经将第三方库导入到我的项目中,我将其称为来自原始项目的 appDelegate 的主 ViewController。我正在尝试添加一个后退按钮(不更改第三方库的代码)。
我在我的 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/