ios - 在 touchesBegan 中创建 Sprite,然后使用 UIPanGestureRecognizer 移动但延迟很小

标签 ios ios7 sprite-kit

我正在使用 SpriteKit 创建一个应用程序,它在 touchesBegan 中创建一个 SKSpriteNode 对象,然后当您在屏幕上平移时,它移动对象。

但是,当我触摸屏幕时, Sprite 会按预期创建,然后当我移动手指时; Sprite 在同一个地方停留一小段时间,然后移动到我手指所在的位置。

我的代码如下:

-(void)handlePan: (UIPanGestureRecognizer*) gestureRecognizer{

if (([gestureRecognizer state] == UIGestureRecognizerStateBegan) || ([gestureRecognizer state] == UIGestureRecognizerStateChanged))
{

    CGPoint newLocation = [scene convertPointFromView:[gestureRecognizer locationInView:self.view]];
    scene.finger.position = newLocation;


}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
{
    NSLog(@"Ended");

    [scene.finger removeFromParent];
    scene.finger = nil;
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

for (UITouch *touch in touches) {
    CGPoint location = [self convertPointFromView:[touch locationInView:self.view]];
    [self addFingerSprite:location];
}

知道如何解决这个小延迟问题吗?

最佳答案

延迟是由于使用 PanGestureRecognizer 造成的。系统需要一段时间才能识别出正在进行平移。请改用 touchesMoved

关于ios - 在 touchesBegan 中创建 Sprite,然后使用 UIPanGestureRecognizer 移动但延迟很小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655601/

相关文章:

ios - 带Spritekit的Swift-带旋钮的操纵杆教程

swift - SKshapenode 没有响应 Physicsbody

ios - 图形上下文的概念与文件句柄非常相似吗? (在 iOS 和其他系统上)

objective-c - 达到内存限制时 NSCache 崩溃(仅在 iOS 7 上)

ios - 调度队列和 NSOperation 队列

ios - 使用 fileNamed 初始化 SKAudioNode 返回 nil

iphone - 在 iphone 的谷歌地图上绘制路线

ios - 使用 quickblox 注册/注册用户?

iphone - 为什么我的对象没有被添加到数组中?

iOS 7 状态栏与 NavigationBar 冲突