我有一个要求,我的视图对象必须检测各种动作,如Tap,Swipe,pinch,Pan。
如何在SKSpriteNode object
上添加手势识别器?它甚至可能吗?
答案 0 :(得分:1)
是的,这是可能的。 SKNode类有漂亮的UITouch方法。
- (CGPoint)locationInNode:(SKNode *)node;
- (CGPoint)previousLocationInNode:(SKNode *)node;
例如
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
CGPoint beganT = [[touches anyObject]locationInNode:self];
//do something
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
CGPoint draggedT = [[touches anyObject]locationInNode:self];
//do something
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
CGPoint endedT = [[touches anyObject]locationInNode:self];
//do something
}
确保您已启用userinteraction!
[self setUserInteractionEnabled:YES];