当我触摸UIButton
时,不会调用touchesBegan
,touchesMoved
和touchesEnded
方法。我想在连续触摸发生时执行事件,并在触摸结束时取消事件。
答案 0 :(得分:0)
您可以使用UIButton控制事件跟踪UIButton触摸开始和触摸结束。
- (void)viewDidLoad {
[super viewDidLoad];
[self.button addTarget:self action:@selector(touchStarted:) forControlEvents:UIControlEventTouchDown];
[self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpInside];
[self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpOutside];
}
- (void)touchStarted:(id)sender {
NSLog(@"Touch started");
}
- (void)touchEnded:(id)sender {
NSLog(@"Touch ended");
}