我有,我有几个大按钮,我设置了这样的观点:如何通过按钮和TouchUpInside有两种不同的SWIPE方法?
SwipeButton* btn = [[[SwipeButton alloc] initWithFrame:CGRectMake(55, 0, 300, 50)] autorelease];
btn.tag = k;
[btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"titleBackground.png"]]
forState:UIControlStateNormal];
[btn addTarget:self
action:@selector(indexAction:)
forControlEvents:UIControlEventTouchUpInside];
我希望能够要么触摸这些按钮,然后火的indexAction方法,或者 - 如果刷卡被认可 - 发射另一种方法。
我以为我的子类UIButton有滑动通过,但这不是一个真正的解决方案,因为现在两个滑动和点击被识别,所以这两个方法激发。
有没有办法解决这个问题?我如何优先扫描,如果没有SWIPE,只允许touchup内侧?
任何帮助将非常感激。
这里是我的子类的UIButton:
#import "SwipeButton.h"
@implementation SwipeButton
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.superview touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self.superview touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self.superview touchesEnded:touches withEvent:event];
}
@end
您是否尝试过[UIGestureRecognizer](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html)类? – 2011-05-24 08:52:30
@尼克韦弗:谢谢,尼克。我没有使用UIGestureRecognizer,因为我想定制刷卡需要多长时间。因此,我使用 - (void)touchesEnded:(NSSet *)触及事件:(UIEvent *)事件...但我想使用GestureRecognizer也没有什么坏处。 – 2011-05-24 12:20:07
为什么要投票?我想这是一个愚蠢的问题,但真的,我试图认真思考。 – 2011-05-24 12:20:50