【发布时间】:2012-03-10 07:08:20
【问题描述】:
我在 UIView 中实现了以下事件处理程序:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.multipleTouchEnabled = YES;
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray* touchObjects = [[event allTouches] allObjects];
for(int i=0; i<[touchObjects count]; i++)
{
touch = (UITouch*)[touchObjects objectAtIndex:i];
curPoint = [touch locationInView:self];
NSLog([NSString stringWithFormat:@"begin = %f,%f",curPoint.x,curPoint.y]);
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint curPoint;
for (UITouch *touch in touches)
{
curPoint = [touch locationInView:self];
NSLog([NSString stringWithFormat:@"ended = %f,%f",curPoint.x,curPoint.y]);
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//logging touches
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
//logging touches
}
问题是我偶尔不会收到“touchesEnded”(或touchesCancelled)事件。我总是收到“touchesBegan”和“touchedMoved”事件。
我已经登录了这些方法,因此我 100% 确定我偶尔不会收到我期待的“touchesEnded”(或 touchesCancelled)事件。
多点触控已启用。
有人知道为什么会这样吗?当我使用这些事件删除子视图时,接收这些事件非常重要。
有解决办法吗?是否可以查询当前触摸的视图(或窗口)?
【问题讨论】:
-
如果您向我们展示您的实际源代码会更好,因为它可能包含您的假源代码没有的问题。
-
更新了代码。真的就这么简单。顺便说一句:iPhone 4,iOS 5.0.1。多次触摸更容易重现,但偶尔一次触摸仍会发生。
-
是否有查询 UIView、UIWindow 或其他当前触摸的方法?
标签: ios objective-c uiview touches