简体   繁体   English

如何在StackView中找到视图的Superview / parentViewController

[英]How can i find the superview/parentviewcontroller of a view inside a stackview

Hopefully this isn't too confusing. 希望这不会太令人困惑。

I have a main view controller ( MainView ) with a stackview at the bottom of the view and inside the stackview I have three views. 我有一个主视图控制器( MainView ),该视图的底部有一个stackview,而在stackview内部,我有三个视图。 Inside one the views (lets call it footerView ) i'm adding a little tooltipView - and because footerView is nestled inside a stackview at the bottom of MainView - it's got some overlap with the other views. 在其中一个视图中(我称它为footerView ),我添加了一个小工具tooltipView -并且由于footerView嵌套在MainView底部的stackview内-它与其他视图有些重叠。 I want to tell the tooltipView to be on top of all the views but it's not working. 我想告诉tooltipView在所有视图之上,但是它不起作用。 Inside footerView - it has no superview (I presume because it's inside a stackview) so I can't use parentView.bringSubviewToFront(childView) . footerView内部-它没有superview (我想是因为它在stackview内部),所以我不能使用parentView.bringSubviewToFront(childView)

What could I do instead? 我该怎么办呢? Is delegation through the layers the only way? 通过层级委派是唯一的方法吗?

You can manually set the zPosition of each layer. 您可以手动设置每个图层的zPosition The default value is 0 so you may not get the desired value you want without manually controlling it. 默认值为0,因此如果不手动控制,可能无法获得所需的值。 As an example you could try 例如,您可以尝试

tooltipView.layer.zPosition = 1 tooltipView.layer.zPosition = 1

or 要么

tooltipView.layer.zPosition = .greatestFiniteMagnitude tooltipView.layer.zPosition = .greatestFiniteMagnitude

Setting it to 1 will make it above other views that default to 0 or setting it to .greatestFiniteMagnitude will always have it at the front. 将其设置为1将使其高于其他默认设置为0的视图,或将其设置为.greatestFiniteMagnitude始终将其置于最前面。

Check out this answer on zPostion and Apple's documentation on zPostion . 在zPostionApple的zPostion文档中查看此答案

Tommy's answer did help but another thing that helped was that I was creating my tooltipView before footerView had finished being set up - hence why the superview was nil . 汤米的回答做了帮助,但另一件事,帮助是,我创造我tooltipViewfooterView已经完成正在建立-因此,为什么superviewnil I moved the initialisation of tooltipView to be inside func layoutSubviews() and it works. 我将tooltipView的初始化tooltipViewfunc layoutSubviews()内部,并且可以正常工作。

But ALSO make sure you untick clip to bounds . 但是还请确保您取消勾画clip to bounds This is why no matter what i did with zPosition made no difference 这就是为什么无论我对zPosition做什么都没有区别的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin iOS。 我可以在stackView控件(作为stackview的项)内使用集合视图吗? - Xamarin iOS. Can I use collection view inside of stackView control (as item of stackview)? 我如何设置另一个分布均匀填充的另一个stackview内部的stackview的高度 - How can i set the height of stackview present inside another stackview whose distribution is fill equally distribution 如何更改 StackView 中存在的视图的高度 - How can I change height of the view which is present in StackView 如何在堆栈视图中使textview可滚动并保持可见? - How can I have textview as scrollable inside a stackview and keep it visible? 如何以编程方式更改 stackView 内单个 UIView 的高度? - How can I change the height of a single UIView inside of a stackView progromatically? 如何将自定义Popover视图控制器与Xamarin.iOS中的ParentViewController中心对齐? - How can I align my custom Popover view controller to center of ParentViewController in Xamarin.iOS? 如何在“ parentViewController”中显示模式视图? - How to present modal view in “parentViewController”? 限制超视图内的视图 - restrict a view inside the superview 从自定义视图内的UITextFields访问ParentViewController - Accessing ParentViewController from UITextFields inside a custom View 如何将UICollectionViews放入stackView中? - How can I put UICollectionViews in stackView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM