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)
任何想法可能是什麼問題?
謝謝!
顯示你的一些代碼或IB的調整限制/幀。你在使用自動佈局嗎? – toddg
@toddg我已經添加了滾動視圖和按鈕的代碼。請看看 –
屏幕底部是否有按鈕?也許你遇到了這個問題:http://stackoverflow.com/a/23047708 – toddg