2017-04-16 103 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 

然后根据

我希望这有助于