UILongPressGestureRecognizer 仅调用第二次
这是我的问题,当我使用 UILongPressGestureRecognizer 时,它只在第二次起作用...我按 3 秒按钮,它不起作用,但第二次我按 3 秒按钮,它工作正常...一些想法?
-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}
-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
[boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
[boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}
感谢所有的朋友。
此致
It is my problem, when i used UILongPressGestureRecognizer, it only works in the second time... I push 3 seconds the button and it dont work, but the second time that i push 3 second the button it works fine... Some idea?
-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}
-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
[boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
[boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}
Thanks for all friends.
Best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为第一次手势没有添加到按钮,您将其添加到用户操作中..因此,将手势添加到之前的按钮,例如在 viewDidLoad 中。
because in the first time the gesture is not added to the button you add it on the user action .. so add the gestures to the buttons before that for example in the viewDidLoad.