简体   繁体   English

Touches开始覆盖touchUpInside操作

[英]TouchesBegan overriding touchUpInside actions

I've implemented a custom UIButton and in order for me to handle LongPress events (without using Gesture Recognizers) I had to use touchesBegan: , touchesEnded: on my class. 我实现了一个自定义UIButton,为了处理LongPress事件(不使用Gesture Recognizers),我必须在类上使用touchesBegan:touchesEnded: Problem is that now the regular button events aren't working. 问题在于现在常规的按钮事件不起作用。 I'm wondering what's causing this and how I could avoid it? 我想知道是什么原因造成的,如何避免呢?

The touch based events are working but the previous actions I had for touchUpInside: are no longer functional. 基于触摸的事件正在运行,但我之前对touchUpInside:操作不再起作用。

Thanks 谢谢

don't use touchesBegan: for longpress, use this gesture recognizer! 不要使用touchesBegan:对于长按,请使用此手势识别器!

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]     initWithTarget:self action:@selector(longTap:)];
[view addGestureRecognizer:longPressGesture];
[longPressGesture release];

-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer{
    NSLog(@"gestureRecognizer= %@",gestureRecognizer);
    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
        NSLog(@"longTap began");
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM