2017-04-16 112 views
1

我有一個UIScrollView其上有7 UIButton s。UIScrollView的一部分不響應觸摸

5個按鈕工作正常,但其他兩個(滾動視圖需要滾動按鈕才能到達)在大多數時間不起作用(如果我點擊很多次,有時他們有時會工作,但大多數他們沒有)。

我試着增加contentSize,而且按鈕仍然不起作用。

我試着改變按鈕的x位置,它們都起作用,所以問題肯定是關於scrollView中的位置。

代碼:

滾動視圖:

self.buttonsScrollView = UIScrollView(frame: self.bounds) 
self.buttonsScrollView?.frame.origin.y = (self.window?.frame.size.height)! - self.bounds.size.height 
self.buttonsScrollView?.showsHorizontalScrollIndicator = false 
self.buttonsScrollView?.canCancelContentTouches = true 
self.buttonsScrollView?.clipsToBounds = false 

按鈕(X7)

let buttonX = UIButton(frame: CGRect(x: previousButton.frame.origin.x + spaceBetweenButtons, y: buttonsYPosition, width: buttonSize, height: buttonSize)) 
buttonX.setImage(UIImage(named: "buttonsXImage"), for: UIControlState()) 
buttonX.tag = 0 
buttonX.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside) 
let buttonXRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didDragButton)) 
buttonX.addGestureRecognizer(buttonXRecognizer) 

任何想法可能是什麼問題?

謝謝!

+0

顯示你的一些代碼或IB的調整限制/幀。你在使用自動佈局嗎? – toddg

+0

@toddg我已經添加了滾動視圖和按鈕的代碼。請看看 –

+0

屏幕底部是否有按鈕?也許你遇到了這個問題:http://stackoverflow.com/a/23047708 – toddg

回答

1

你的問題是包含scrollView的觀點,你可以剪輯您的容器視圖,看看你的兩個問題羣按鈕仍然存在,或者您也可以設置邊框的顏色和寬度您scrollView容器視圖

檢查裁剪包含您的滾動視圖視圖

self.scrollViewSuperView.clipsToBounds = true 

,或者你可以設置scrollViewSuperView邊框的寬度和顏色

self.scrollViewSuperView.borderColor = UIColor.red.cgColor 
self.scrollViewSuperView.borderWidth = 1 

然後根據

我希望這有助於