我有两个自定义 uibuttons。
@interface myButton : UIButton
我覆盖了几种方法,例如
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// do something
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
[self.nextResponder touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
if (!CGRectContainsPoint(self.bounds, touchPoint)) {
[self touchesCancelled:touches withEvent:event];
}
return;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// do something
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
return;
}
我想要的是,当我触摸一个按钮时,我可以继续将触摸移动到另一个按钮。当触摸超出我触摸的第一个按钮的范围时,我厌倦了调用 touchesCancelled。所以我“认为”然后我移动到另一个按钮,这将是一个新的触摸事件。但它不是这样工作的。
我做错什么了吗?或者 touchesCancelled 方法不是这样使用的?提前致谢!