【问题标题】:Bring overlapping UIViewController to front将重叠的 UIViewController 放在前面
【发布时间】:2013-01-20 00:08:59
【问题描述】:

我目前在我的 iPhone 应用程序中同时运行三个视图控制器。
我使用slidingView

这是我的图片:

当我点击表格视图单元格时,我想像这样打开一个新的视图控制器:

(鸡蛋代表一个新的视图控制器。

但是你可以看到我的橙色视图控制器在前面。

我该如何更改?

我用来打开egg-viewcontroller的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIViewController *boxView = [self.storyboard instantiateViewControllerWithIdentifier:@"BoxView"];
    boxView.modalPresentationStyle = UIModalPresentationFormSheet;
    boxView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    boxView.view.frame=CGRectMake(-50, 5, 300, 470);
    [self.view addSubview:boxView.view];
    //[self.view bringSubviewToFront:boxView];

}

【问题讨论】:

    标签: ios uiviewcontroller containment uimodalpresentationstyle


    【解决方案1】:

    这应该很容易,您需要您的父视图控制器(即橙色控制器)来添加新视图控制器的子视图。您通常可以通过 [self.parentViewController addSubview:boxView.view] 做到这一点。但由于您使用的是 ECSlidingViewController ,您可以这样做: [self.slidingViewController.topViewController.view addSubview:boxView.view]

    当然,您需要相应地调整新 ViewController 的框架。

    【讨论】:

    • 没问题马克!为了能够关闭,我现在想到的是您需要向视图添加一个按钮/点击手势,当您单击/触摸它时,您将触发 [self.boxView.view removeFromSuperView]。我建议您将新的视图控制器(即 boxView 控制器)声明为属性,例如@property (strong,nonatomic)UIViewController *boxView,因为你会想像 self.boxView 一样访问它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2019-07-20
    相关资源
    最近更新 更多