Swift:将视图从堆栈视图移到最前面 [英] Swift: Bring View from Stack View to front

查看:776
本文介绍了Swift:将视图从堆栈视图移到最前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个堆栈视图,其视图为:1、2、3、4和5

I got a Stack View with view: 1,2,3,4 and 5

在所有其他视图上方,寻找一种方法将Image View4从View4移到Stack视图中.我之所以需要它,是因为我正在将Image View4移到view3中的Image View3上.

Looking for a method to bring the Image View4 from view4 in the Stack view, above all the other views. The reason I need this is because I am moving the Image View4 over the Image View3 in view3.

我试图在视图层次结构中将view3移到view4之上,但这只是交换了它们在Stack View中的位置.

I have tried to move view3 over view4 in the view hierarchy, but that just swaps their places in the Stack View.

推荐答案

来自 UIStackView文档:

subviews数组中[视图的顺序]定义了子视图的Z顺序.如果视图重叠,则索引较低的子视图将出现在索引较高的子视图之后.

The order of [the views in] the subviews array defines the Z-order of the subviews. If the views overlap, subviews with a lower index appear behind subviews with a higher index.

因此,由于堆栈视图的arrangedSubviews数组中的所有视图也都在堆栈视图的subviews数组中,因此您应该能够使用标准的UIView API重新排列视图的z顺序:

So since all views in the stack view's arrangedSubviews array are also in the stack view's subviews array, you should be able to use the standard UIView APIs to rearrange the views z-order:

  • bringSubview(toFront:)
  • sendSubview(toBack:)
  • exchangeSubview(at:withSubviewAt:)
  • bringSubview(toFront:)
  • sendSubview(toBack:)
  • exchangeSubview(at:withSubviewAt:)

我不知道这是否可以在Interface Builder中完成.

I don't know whether this is possible to do in Interface Builder or not.

这篇关于Swift:将视图从堆栈视图移到最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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