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