在新库ViewController上添加UIButton

时间:2015-05-27 09:11:21

标签: ios objective-c xcode xcode6

我已将第三方库导入到我的项目中,我将其称为来自我原始项目的appDelegate的主ViewController。我正在尝试添加backButton(不更改第三方库的代码)。

我在AppDelegate中使用以下

呈现VC
ABSViewController *abs = [[ABViewController alloc] init];
    [self.window.rootViewController presentViewController:abs
                                                 animated:NO
                                               completion:nil];

然后我尝试用下面的程序方式添加我的UIButton,但即使调用了“带有子视图”,也不会出现在前面。

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)后面设置的

1 个答案:

答案 0 :(得分:1)

我认为你需要在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];
}];