向动态添加的UIScrollView视图上的按钮添加选择器 [英] Add selector to button on UIScrollView views added dynamically

查看:64
本文介绍了向动态添加的UIScrollView视图上的按钮添加选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIScrollView,其中n个视图是通过归档存储的元数据动态添加的.我有一个PressGesture来制作摆动动画(例如iOS删除应用程序的方式),我想在ScrollView的每个子视图上添加一个按钮,以从ScrollView和文件中删除它.

我的问题是将目标添加到按钮.按下它们时,不会调用选择器(在UIScrollView的UIViewController父级上).

我该如何完成?建议使用其他方法吗?

谢谢.

解决方案

为视图设置动画时,该视图将停止响应用户输入.而且,如果您的按钮位于动画视图中,则绝对不会调用选择器.

解决方案是将您的摆动视图包装到一个透明的超级视图中,然后在该超级视图内放置删除"按钮.如果您希望按钮也摆动",则需要在摆动视图中放置一个表示按钮的图像.在包装器内放了一个透明的自定义"按钮,实际上,该按钮会在用户点击时做出反应.

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.

解决方案

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.

这篇关于向动态添加的UIScrollView视图上的按钮添加选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆