ios - 在新库 ViewController 上方添加 UIButton

标签 ios objective-c xcode xcode6

我已经将第三方库导入到我的项目中,我将其称为来自原始项目的 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/

相关文章:

iOS performSelector onThread 与对象

javascript - 如何从javascript调用swift函数

ios - 使选定的文本字符串 View 粗体、斜体、下划线像 iOS 的 native "Notes"应用程序

iphone - 更改 rootviewcontroller +[NSNotificationCenter dictationViewClass] 后出错

ios - 大小类和自动布局混淆多个设备

objective-c - 管理 NSSearchfield 上的键盘事件,无需子类化

ios - swift : Use NSPredicate to filter NSMutableArray of NSMutableDictionary

Objective-C中的符号和花括号,@{...}是什么意思?

ios - 使用 sortDescriptors 基于另一个 NSArray 对 NSArray 进行排序

ios - 为什么我的 UIView 背景在切换到下一个 View 时会变形?