简体   繁体   English

如何添加子视图以使其与另一个视图重叠?

[英]How to add subview so that it overlaps another view?

I have the following subview我有以下子视图

    webView = WKWebView(frame: CGRect(x: 3, y: horizontalLine.frame.maxY + 8, width: self.view.frame.width-6, height: CGFloat(self.view.frame.height - 150)))
    webView.navigationDelegate = self
    self.view.addSubview(webView)
    

I want to add the following subview on top of it (not inside it).我想在它上面添加以下子视图(而不是在它里面)。

 textSizeChangeView = UIView(frame: CGRect(x: 0, y: textBtn.frame.maxY, width: self.view.frame.width, height: 100))
    textSizeChangeView.backgroundColor = UIColor(red: 0.97, green: 0.98, blue: 0.98, alpha: 1.00)
    
    let mySlider = UISlider(frame:CGRect(x: 10, y: 0, width: self.view.frame.width - 20, height: 30))
    self.textSizeChangeView.addSubview(mySlider)
    
    mySlider.center = self.textSizeChangeView.center
    
    mySlider.minimumValue = 1
    mySlider.maximumValue = 2
    mySlider.isContinuous = true
    mySlider.tintColor = UIColor(red: 0.33, green: 0.79, blue: 0.93, alpha: 1.00)
    textSizeChangeView.isHidden = true
    mySlider.addTarget(self, action: #selector(self.sliderValueChanged(sender:)), for: .valueChanged)

    self.view.addSubview(self.textSizeChangeView)

How can I do this?我怎样才能做到这一点?

The order of adding subviews matters.添加子视图的顺序很重要。

If you want to make sure that textSizeChangeView will be on top of webView in case of overlapping then you need to make sure that self.view.addSubview(webView) is called before self.view.addSubview(self.textSizeChangeView) .如果您想确保textSizeChangeView在重叠的情况下位于webView之上,那么您需要确保在self.view.addSubview(self.textSizeChangeView)之前调用self.view.addSubview(webView) ) 。

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

相关问题 如何将视图添加到子视图? - how add view to subview? 添加子视图以使其覆盖UITabBar而不覆盖UINavigationBar - Add subview to view so that it overlays the UITabBar but not the UINavigationBar 如何将故事板中的子视图添加到Swift 4代码中的另一个视图中? - how to add a subview that is in story board to another view that is in codes in swift 4? 在另一个视图控制器中将视图控制器添加为子视图 - Add a view controller as a subview in another view controller 将UIViewControllers视图添加为另一个UIViewController视图的子视图 - Add UIViewControllers View as a subView of another UIViewController view 如何将子视图添加到另一个viewcontroller? - How to add subview to another viewcontroller? 将集合视图控制器添加到另一个控制器作为子视图 - add a collection view controller to another controller as subview 如何将子类添加为子视图,以便在superview前面设置子视图的背景 - How to add a subclass as a subview so that background of subview is set in front of superview 如何以编程方式添加约束,以使视图的高度恰好适合其最后一个子视图的底部? - How to add a constraint programmatically so that the height of a view just fits the bottom of its last subview? 如何在iOS中添加与表视图重叠的视图 - How to add a view that overlaps a tableview in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM