UIButton is not working/Clickable in UIScrollView

2019-07-04 05:22发布

问题:

I am using auto layout with UIScrollView.

Main UIView Height = 1300

ContentView (within UIScrollBar) UIView = 1100

The ConetntView contains a button at the bottom. It is completely visible but when I click it, it does not work.

Constraints are :

1) ScrollView leading, trailing, top & bottom with main UIView

2) ContantView leading, trailing, top & bottom with UIScrollView

3) Equal height constraint between ContentView & main UIView

Please help.

回答1:

So, according to your comment this is layout issue. I think root cause is 3rd constraint. Please remove it and create another constraint for Content View Height with hardcoded height value (like 'Height - (1315) - Content View'). If you need to have flexible height for Content View, i.e. not hardcoded in the Storyboard, then please modify it programmatically.



回答2:

I had to provide (-)ve value for bottom space of the ContentView from the superview. It did the job. Initially it was set to zero and because of this there was a large extra space below the bottom and it made the scrolling larger that was not desired.

I have tested it in all the simulators - 4s to 6+ and it is working fine.

Thanks to Nikolay for his continuous help.

Also as I am completely new to iPhone development so I do not know whether my workaround is correct or not. So if there is another solution to the problem then please let me know.