Add selector to button on UIScrollView views added dynamically

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-03 06:39:12

问题


I have an UIScrollView with n views added dynamically from metadata stored by archiving. I have a PressGesture to make wobble animation (like iOS deleting apps way) and i want to add a button to every subview on the ScrollView for deleting it from the ScrollView and from files.

My problem is for adding the target to the buttons. When they are pressed, the selector (on the UIViewController parent of the UIScrollView) are not called.

How can I get this done? Any other approach is suggested?

Thanks in advance.


回答1:


When you animate the view it stops responding to user input. And if your button is located inside animated view, it will definitely not call the selector.

The solution would be to wrap your wobbling view into a transparent superview and then place Delete button inside that superview. If you need your button to be also "wobbling" then you need to put an image that represents button inside your wobbling view. And inside wrapper put a transparent Custom button, that will in fact react on user tap.



来源:https://stackoverflow.com/questions/12354919/add-selector-to-button-on-uiscrollview-views-added-dynamically

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