我有两个自定义的uibuttons。ios触摸从一个按钮移动到另一个按钮
@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方法不是用于这样的? 在此先感谢!
我相信'当你移动你的手指从第一个按钮的面积touchesCanceled'已经被调用。它不会在第二个按钮上调用touchesBegan,因为您没有再次放下手指。为什么不使用手势识别器呢? – 2013-03-26 16:01:42
您正在将事件从一个按钮传递到另一个按钮。一个按钮上的事件位置与其他按钮不匹配,因此显然与您的代码一样,甚至会在其他按钮中取消。 – nkongara 2013-03-26 17:15:02