h文件
#import <Foundation/Foundation.h>
@interface HFTouchButton : UIButton
{
}
@end
m 文件
#import "HFTouchButton.h"
@implementation HFTouchButton
bool touchMoved;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
touchMoved = NO;
[[self superview] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
touchMoved = YES;
[[self superview] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self superview] touchesEnded:touches withEvent:event];
if (!touchMoved)
{
[super touchesEnded:touches withEvent:event];
}
}
@end