0

I have a ScrollView, and a container view inside of it. UIButtons are inside of the container view. When I run the program, UIButtons that are at the end of the ScrollView are unresponsive. UITextFields are responsive. Yet, after tweaking around with frames I made sure that both origin and hightXwidth of UIScrollView and container view are matched. I checked it with print statements. Some of the settings:

scrollView.isExclusiveTouch = true
scrollView.delaysContentTouches = false
scrollView.isUserInteractionEnabled = true

ScrollView's content size:

let hightForScrollMenu: CGFloat = 120
scrollView.contentSize = CGSize(width: scrollView.frame.size.width, height: scrollView.frame.size.height+hightForScrollMenu)

Output view: enter image description here

When checking:

viewInsideScrollView.frame.size.height = scrollView.frame.size.height
print("Zhenya: ScrollView's frame height is:\(scrollView.frame.size.height) and its origin is \(scrollView.frame.origin)")
print("Zhenya: ViewInsideScrollView's frame heigt is: \(viewInsideScrollView.frame.size.height) and its origin is \(scrollView.frame.origin)")

enter image description here

View Controller attributes:

enter image description here

Main View attributes and constraints:

enter image description here

enter image description here

ScrollView attributes and constraints:

enter image description here

enter image description here

Container View attributes and constraints:

enter image description here

enter image description here

toddg
  • 2,863
  • 2
  • 18
  • 33
Mr_Vlasov
  • 515
  • 2
  • 6
  • 25
  • [FistLink](http://stackoverflow.com/questions/3132147/uibutton-inside-uiscrollview-doesnt-fire-on-tap), [SecondLink](http://stackoverflow.com/questions/16649639/uibutton-does-not-work-when-it-in-uiscrollview), [ThirdLink](http://stackoverflow.com/questions/27820304/uibutton-is-not-working-clickable-in-uiscrollview) – Just a coder Jan 20 '17 at 22:09
  • thanks. Tried those before posting this question. – Mr_Vlasov Jan 20 '17 at 22:48

2 Answers2

1

The Container View is the red view? Well, then obviously the button is outside it. A button outside its superview is untappable.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Yes, the ContainerView is the red view. And it does look like the button is outside of it. However, in the view structure that button is part of the container view. And all of its constraints are connected to container view. – Mr_Vlasov Jan 20 '17 at 22:47
  • I don't care about "look like" (though it was helpful of you to color the views). I don't care about "part of" and "connected to". The red clearly shows that the button _is_ outside of is superview. That makes the button impossible to tap. End of story. Your question is answered. Your question was "the button is not responding". I've told you why. Correctly. – matt Jan 20 '17 at 22:57
-1

The solution was - to set container's view hight to 616. I don't understand why setting its hight to "equal to ScrollView" or fixing it programmatically to equal scrollView's didn't work.

Mr_Vlasov
  • 515
  • 2
  • 6
  • 25