景观模式中的滑动手势问题

时间:2016-06-08 18:41:37

标签: ios objective-c sprite-kit landscape

我一直试图找出一种方法来解决这个问题,没有任何运气。

编程语言是Objective-C,SpriteKit就是技术。

我尝试使用滑动手势在屏幕上进行SKNode移动。 (在横向模式应用中)

问题是当我向左或任何其他方向滑动时,节点将向相反方向移动并使用另一种方法,而不是它应该的方法。看起来iPhone认为它处于纵向模式。我该怎么办?

以下是代码:

内部.h声明节点

SKNode *Main_Character;

内部.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    UISwipeGestureRecognizer *oneFingerSwipeLeft = [[UISwipeGestureRecognizer alloc]
                                                    initWithTarget:self
                                                    action:@selector(SwipedLeft)] ;
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:oneFingerSwipeLeft];

    UISwipeGestureRecognizer *oneFingerSwipeRight = [[UISwipeGestureRecognizer alloc]
                                                     initWithTarget:self
                                                     action:@selector(SwipedRight)] ;
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:oneFingerSwipeRight];

    UISwipeGestureRecognizer *oneFingerSwipeUp = [[UISwipeGestureRecognizer alloc]
                                                  initWithTarget:self
                                                  action:@selector(SwipedUp)] ;
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionUp];
    [[self view] addGestureRecognizer:oneFingerSwipeUp];

    UISwipeGestureRecognizer *oneFingerSwipeDown = [[UISwipeGestureRecognizer alloc]
                                                    initWithTarget:self
                                                    action:@selector(SwipedDown)] ;
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionDown];
    [[self view] addGestureRecognizer:oneFingerSwipeDown];
}

// Methods to make the node move when a swipe is called.
-(void)SwipedDown{
    SKAction *Move = [SKAction moveByX:0.00 y:-50 duration:2];

    [Main_Character runAction:Move];
}

-(void)SwipedUp{
    SKAction *Move = [SKAction moveByX:0.00 y:+50 duration:2];

    [Main_Character runAction:Move];
}

-(void)SwipedRight{
    SKAction *Move = [SKAction moveByX:+50 y:0.00 duration:2];

    [Main_Character runAction:Move];
}

-(void)SwipedLeft{
    SKAction *Move = [SKAction moveByX:-50 y:0.00 duration:2];

    [Main_Character runAction:Move];
}

1 个答案:

答案 0 :(得分:0)

你的复制/粘贴失败了,你需要修改你的setDirections,你只需要设置左,当你想设置其他方向时。