UIButton is not working/Clickable in UIScrollView

邮差的信 提交于 2019-12-12 15:08:33

问题


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.



来源:https://stackoverflow.com/questions/27820304/uibutton-is-not-working-clickable-in-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!