开发者

IPhone UIButton - Swipe vs. Touches

I subclassed a UIButton for custom drawing (overriding drawRect) and some other custom behavior, out of which the following is relevant (and trivial):

  1. If it is pressed (UIControlEventTouchDown) a flag "pressed" is turned on (affects custom drawing, kind of like "highlighted").
  2. If it is released inside (UIControlEventTouchUpInside), my OnClick function is triggered.
  3. If it is released outside (UIControlEventTouchUpOutside), flag "pressed" is turned off.

I now wanted to add an additional behavior to the button so it will recognize swipe gestures (using UISwipeGestureRecognizer), and affect the button content. The problem is that when preforming a swipe gesture, the TouchDown fires, as it really should, causing the button to appear "pressed", which is not my intention during a swipe.

My question is if there is an elegant way to avoid this. Perhaps something similar to DelaysContentTouches of a scroll view, that will separate the swipe behavior from the pressing behavior. The only other alternative I can see, is messing around with timers my self开发者_高级运维, which I would prefer avoiding if possible.

Thanks!


DannyA. Here is my solution:

Use also UITapGestureRecognizer

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapAction:)];

Then, implement this in didTapAction: selector

[UIButton setHighlighted:YES];

[UIButton performSelector:@selector(setHighlighted:) withObject:NO afterDelay:0.15];

That work fine for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜