Swift: Bring View from Stack View to front

谁说胖子不能爱 提交于 2019-12-04 15:28:11

From the UIStackView documentation:

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.

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:)

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

Remove the image from the stack view and add it to the same view that contains the stack view as a subview, using addSubview(_:). That will put it on top of all other views. You could also use insertSubview(_:aboveSubview:) to insert it directly above the stack view.

You'll need to add constraints to the new view so that it is positioned where you want it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!