ios如何潘没有触摸操作Sprite工具包中得到执行?

发布时间: 2017/4/3 16:28:45
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

touchesBegan 我有我的逻辑为单一的触摸。我想添加改变相机位置与泛的能力。泛,我使用 touchesMoved 。一切都是种好,但一旦我能胜任,触摸行动获取太执行。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        NSArray *sprites = [self nodesAtPoint:location];
        for (SKSpriteNode *sprite in sprites)
        {
            //*
            //*  How to stop executing this block when panning? 
            //*
        }

    }
}

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    CGPoint previousPosition = [touch previousLocationInNode:self];
    CGPoint translation = CGPointMake((-1)*(positionInScene.x - previousPosition.x), (-1)*(positionInScene.y - previousPosition.y));
    CGPoint cameraPos = [self camera].position;

    [self camera].position = CGPointAdd(cameraPos, translation);

}

解决方法 1:

看看如何使用内置于 IOS,用它你泛手势将有选项允许它也执行触摸事件或不。

我会给你答案,使用视图控制器,您可以使用它在其他地方虽然

客观的 c:

开放 ViewController.h 并添加以下声明︰

@interface ViewController : UIViewController<UIGestureRecognizerDelegate>

...

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer;

然后实现它在 ViewController.m 中,如下所示︰

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {

    CGPoint translation = [recognizer translationInView:self.view];
    recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, 
                                     recognizer.view.center.y + translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view];

}

http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more

在这一点上可以链接它通过 UI 像上述,本教程中或在开始中某处声明

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];

Swift:

class ViewController : UIViewController, UIGestureRecognizerDelegate

......然后在您的代码

@IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
  let translation = recognizer.translationInView(self.view)
  if let view = recognizer.view {
    view.center = CGPoint(x:view.center.x + translation.x,
                          y:view.center.y + translation.y)
  }
  recognizer.setTranslation(CGPointZero, inView: self.view)
 }

http://www.raywenderlich.com/76020/using-uigesturerecognizer-with-swift-tutorial

在这一点上你可以链接它通过 UI 像上述,本教程中或在像 init 的开始阶段中某处声明︰

let pan = UIPanGestureRecognizer(target: self, action: "handlePan:")
self.view.addGestureRecognizer(pan);
官方微信
官方QQ群
31647020