如何在Swift的另一个视图前面显示视图? [英] How can I bring a view in front of another view, in Swift?

查看:506
本文介绍了如何在Swift的另一个视图前面显示视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的视图在IB中的组织方式,顶部 - >应用程序启动时的底部。

Below are how my views are organized in IB, top->bottom when the app is started.

用户可以做一些事情使类别表视图标题暂时扩展到名称视图 - 但是一旦这样做,分配给类别表的.TouchDown操作查看标题不再适用于与名称视图重叠的任何位置(即,用户可以在不与名称视图重叠的任何位置点击标题,它仍然有效)。

The user can do something to make "Category Table View Header" temporarily expand over "Name View" - however once doing so, the .TouchDown action assigned to "Category Table View Header" no longer works wherever it overlaps with "Name View" (i.e., the user can tap the header anywhere it doesn't overlap with name view and it still works).

我知道这可能令人困惑,所以我抽出了一些方块。左侧是原件,右侧是用户操作后 - 问题出在右侧,红色框上的操作仅在用户点击下半部而不是上半部时才有效。

I know that may be confusing, so I drew out some boxes. On the left is the original, right is after user action - problem is on the right the action on the red box only works if the user taps the bottom half, not the top half.

我的猜测是因为标题层次结构中的标题低于名称视图,但是如果不弄乱一堆约束,我就很难改变它。

My guess is its because the header is lower in the view hierarchy than the name view, but it would be hard for me to change that without messing around with a bunch of constraints.

我也试过设置nameView.hidden = true,但这不起作用。

I also tried setting nameView.hidden = true, but that doesn't work.

推荐答案

如果你想把一个子视图带到前面,你可以使用:

If you want to bring a subview to the front, you can use:

self.view.bringSubviewToFront(yourView)

SWIFT 3更新

self.view.bringSubview(toFront: yourView)

将视图发送回: -

Send view to back:-

self.view.sendSubview(toBack: yourView)

这篇关于如何在Swift的另一个视图前面显示视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆