2017-05-13 31 views
0

我有Ucodeutton无法触摸/点击的UI ScrollView中的Xcode 8和Swift 3 UIButton问题。故事板的结构就像这样。Swift 3无法触摸UIScroll底部的UIButton

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

而这条代码用于使滚动使用动态标签。

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

一切都设置为故事板中的默认设置。是否有另一种配置来解决这个问题?

+1

请显示您的设置的完整代码 – dymv

回答

2

很可能您的UIButton不在其超监视范围内。这通常是我看到这种情况时的问题。尝试设置UIButton的超级视图的背景颜色为红色或其他东西,看看按钮是否在红色区域内。

+0

您是对的,当我给它背景时,内容视图达到滚动视图的底部。但是,我不明白为什么会这样。我尝试打印以确保内容视图高度与滚动视图高度和标签+按钮高度相同,但高度相同。我应该如何更新内容视图高度? – Djamware

+0

最后,我把这个“self.contentView.translatesAutoresizingMaskIntoConstraints = true”后scrollView调整大小,按钮的作品。但它超过了宽度scrollview和它的内容,即使我添加了这一行“contentViewWidthConstraints.constant = view.frame.width” – Djamware