1

I have a UIScrollView with 7 UIButtons on it.

5 buttons are working fine but the other two (which the scroll view needs to be scrolled for the buttons to be reached) doesn't work most of the times (if I tap a lot of times they sometimes work but most of the time they don't).

I've tried to increase the contentSize and the buttons still don't work.

I've tried to change the x position of the buttons and they both work so the problem is definitely about the position in the scrollView.

Code:

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

buttons (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)

Any ideas what can be the problem?

Thank you!

FS.O6
  • 1,394
  • 2
  • 20
  • 42

1 Answers1

1

Your problem is the view that contains your scrollView, you can clip your container view, and see if your two problematics buttons are still there, or you can set border color and width for your scrollView container view

check clipping the view that contains your scrollView

self.scrollViewSuperView.clipsToBounds = true

or you can setup scrollViewSuperView border width and border color

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

Then adjust your constraints/frames according

I hope this helps

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55