2017-02-06 56 views
0

我有滾動視圖。在側面滾動視圖中,我有一個容器視圖,它具有拖尾,前導,頂部和底部約束以及相等的高度。我正在動態添加視圖。我更新了內容大小scrollView的底部內容不是無法響應觸摸事件

viewWillLayoutSubviews如下。

override func viewWillLayoutSubviews() { 
     self.scrollView.contentSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height) 
     self.contentView.frame = CGRect(x: self.contentView.frame.minX, y: self.contentView.frame.minY, width: self.contentView.frame.width, height: 2500) // code to update the contentView's frame where 2500 is a dummy value 
     self.contentView.clipsToBounds = true 
    } 

現在,我可以滾動,直到我的容器視圖的最後一個子視圖。但問題是最後3個子視圖沒有響應觸摸事件。

我嘗試了以下方法,但失敗了。

  • 還更新了containterView的框架
  • 也更新了滾動的框架

沒有工作。 請幫幫我。

+0

使用容器視圖檢查底部3視圖的框架。 –

+0

最後3個子視圖對觸摸事件沒有響應 - >確保isUserInteractionEnabled = true –

+0

isUserInteractionEnabled = true。它已啓用。 @ NhatDinh –

回答

0
func updateFrame() { 
      self.scrollView.contentSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height) 
    self.contentView.translatesAutoresizingMaskIntoConstraints = false 
      self.contentView.frame = CGRect(x: self.contentView.frame.minX, y: self.contentView.frame.minY, width: self.contentView.frame.width, height: 2500) // code to update the contentView's frame where 2500 is a dummy value 
      self.contentView.clipsToBounds = true 
     } 

試試這個。 我假設您的滾動視圖大於內容視圖

+0

沒有結果。 @Rahul Patel –

+0

而不是viewWillLayoutSubviews,手動調用此方法updateFrame –

+0

對不起@Rahul Patel,仍然不能正常工作 –