实现长按按钮并在该按钮顶部显示删除按钮,就像从后台删除应用程序一样
我想实现长按按钮,长按后按钮顶部应出现一个十字按钮,以从添加到表视图中的滚动视图中删除该按钮。
我在网上搜索并实现了 UILongPressGestureRecognizer
。我尝试过它,但我的滚动视图中有很多按钮,我在每个按钮上放置了 UILongPressGestureRecognizer
但我将如何提供参考将按下的按钮添加到选择器方法,以便我可以在该特定按下的按钮上添加十字按钮。
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAppFromList:)];
UIButton *btn=(UIButton *)[cell.contentView viewWithTag:101+i];
[btn addGestureRecognizer:longPressGesture];
[longPressGesture release];
请建议我如何实现这一点。我想要执行该功能,就像我们从 ios 设备或模拟器中删除应用程序一样。
I want to implement a long press on my button and after that long press a cross button should appear on the top of the button to remove that button from scroll view which is added in table view.
I search on web and got UILongPressGestureRecognizer
to implement.I tried with it but I have many button in my scroll view and I put UILongPressGestureRecognizer
on every button but how will I give reference of the pressed button to the selector method so that I can add a cross button on that particular pressed button.
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAppFromList:)];
UIButton *btn=(UIButton *)[cell.contentView viewWithTag:101+i];
[btn addGestureRecognizer:longPressGesture];
[longPressGesture release];
Please suggest me how to implement this.I want to do the functionality just as when we delete an app from ios device or simulator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚做了类似的事情。我检测到 touchDown 事件,安排一个定时方法,在 1 秒后设置一个标志,然后当检测到 touch up 事件时,它检查该标志并调用适当的方法。
I've just done something similar. I detect the touchDown event, schedule a timed method which sets a flag after 1 second, then when the touch up event is detected it checks the flag and calls the appropriate method.
在设置为手势识别器目标的处理程序方法中,您将传递对触发的识别器的引用,例如:
识别器有一个“view”属性,这是识别器附加到的视图。直接使用它或获取该视图的标签,您可以找出按下了哪个按钮。
话虽如此,为每个按钮添加手势识别器似乎是错误的方法。我将创建一个自定义控件并直接处理“touchesBegan”和“touchesEnded”。
In your handler method that you set up as the target of the gesture recognizer you are passed a reference to the recognizer that fired, e.g.:
The recognizer has a 'view' property, which is the view the recognizer is attached to. Use this directly or get the tag of this view and you can work out which button was pressed.
Having said that, adding a gesture recognizer to each button seems the wrong way to do this. I would create a custom control and handle 'touchesBegan' and 'touchesEnded' directly.
在长按识别器的处理程序方法中,使用 view 属性及其标签来识别视图。
In the handler method of the long press recognizer, use the view property and its tag to identify the view.