UIButton with two state - touch and long touch

2019-08-25 05:39发布

I'd like to make a button perform different methods, depending on if the user taps or does a long tap.

I've tried:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(doRewind)];
[uiNextButton addGestureRecognizer:longPress];
[longPress release];

But the app registers my touch only when I touch the button and move the finger a little bit.

What am I doing wrong?

1条回答
甜甜的少女心
2楼-- · 2019-08-25 06:01

If you are setting both a "normal" tap and a "long" tap gesture, there could be interactions between the two of them.

Have you tried setting the minimumPressDuration property for UILongPressGestureRecognizer?

Also, using requireGestureRecognizerToFail: can be useful to make one of the two gesture handler fire only if the other one did not.

Have a look at the relevant document for those two methods.

If this does not help, please, give more details about your view and all the gesture handlers you are defining.

查看更多
登录 后发表回答