我有,我有幾個大按鈕,我設置了這樣的觀點:如何通過按鈕和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