【发布时间】:2013-03-26 15:28:23
【问题描述】:
我有两个自定义 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 方法不是这样使用的? 提前致谢!
【问题讨论】:
-
我相信当您将手指移出第一个按钮区域时,
touchesCanceled已经被调用。它不会在第二个按钮上调用touchesBegan,因为您没有再次放下手指。为什么不使用手势识别器呢? -
您正在将事件从一个按钮传递到另一个按钮。一个按钮上的事件位置将与其他按钮不匹配,因此显然根据您的代码,甚至会在其他按钮中被取消。
标签: ios objective-c cocoa-touch uibutton