繁体   English   中英

点击它时如何将子视图带到前面?

[英]How to bring a subview to the front when you tap it?

我有一个关于它的大约30个子视图的视图。 我想在我的子视图的viewcontroller中添加代码,这样当我点击子视图时,子视图会扩展以填充屏幕。

我正在使用[self.view setFrame:rect]来扩展子视图,这很好用。 问题是其他29个子视图中的一些超出了我刚刚点击的子视图,所以它们仍然可见。

我已尝试从父bringSubviewToFront使用bringSubviewToFront ,但这似乎没有任何效果。 我可以在子视图的viewcontroller类中添加任何代码来实现吗?

bringSubviewToFront应该可以工作,只要确保你正确使用它。 用法是。

[parentView bringSubviewToFront:childView];

使用此代码,即使您不了解superView:

在objective-c中:

[subview.superview bringSubviewToFront: subview];

在快速:

subview.superview?.bringSubview(toFront: subview)

为了便于使用Swift 3中的扩展

extension UIView {

    func bringToFront() {
        self.superview?.bringSubview(toFront: self)
    }

}

在Objective-C中:

[self.superview bringSubviewToFront: subview];

在Swift 2.3中:

self.superview!.bringSubviewToFront(subview)

在Swift 3.1.1中 - Swift 4.1:

superview.bringSubview(toFront: subview)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM