简体   繁体   English

Swift 3无法触摸UIScroll底部的UIButton

[英]Swift 3 Can't touch UIButton on the bottom of UIScroll

I have a problem with Xcode 8 and Swift 3 UIButton inside UI ScrollView which the UIButton can't touch/tap. 我在UIScroll内的Xcode 8和Swift 3 UIButton遇到问题,UIButton无法触摸/轻按。 The structure of storyboard like this. 这样的情节提要的结构。

View
-Scroll View
--Content View
---Content Label (dynamic long content get from API)
---Agree Button

And this lines of codes for making scroll working with the dynamic label. 这行代码可以使滚动条与动态标签一起使用。

override func viewDidLayoutSubviews() {
    let maxLabelWidth: CGFloat = self.contentView.frame.size.width
    let neededSize = self.contentLabel.sizeThatFits(CGSize(width: maxLabelWidth, height: CGFloat.greatestFiniteMagnitude))
    self.contentView.frame.size.height = neededSize.height+self.agreeButton.frame.size.height+300
    self.scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: self.contentView.frame.size.height)
}

Everything is setup as default in the storyboard. 情节提要中的所有内容均默认设置。 Is there another configuration to solve this problem? 是否有其他配置可以解决此问题?

It is highly likely that your UIButton is not within the bounds of its superview. 您的UIButton很可能不在其超级视图的范围内。 That is usually the problem when I see this happen. 当我看到这种情况时,通常就是问题所在。 Try setting the background color of the UIButton's superview to red or something and see if the button is within the red area. 尝试将UIButton的超级视图的背景色设置为红色或其他颜色,然后查看按钮是否在红色区域内。

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

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