h文件
#import<Foundation/Foundation.h>
@interfaceHFTouchButton :UIButton
{
}
@end
m 文件
#import"HFTouchButton.h"
@implementationHFTouchButton
booltouchMoved;
- (id)initWithFrame:(CGRect)frame
{
self= [superinitWithFrame:frame];
if(self) {
// Initialization code
}
returnself;
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
touchMoved=NO;
[[selfsuperview]touchesBegan:toucheswithEvent:event];
[supertouchesBegan:toucheswithEvent:event];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
touchMoved=YES;
[[selfsuperview]touchesMoved:toucheswithEvent:event];
[supertouchesMoved:toucheswithEvent:event];
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
[[selfsuperview]touchesEnded:toucheswithEvent:event];
if(!touchMoved)
{
[supertouchesEnded:toucheswithEvent:event];
}
}
@end
本文详细介绍了如何使用Objective-C实现自定义触摸按钮类HFTouchButton,包括初始化方法、触摸开始、移动和结束事件的处理。
7766

被折叠的 条评论
为什么被折叠?



