横向模式下滑动手势的问题

Problems with Swipe Gesture in Landscape Mode

我一直在想办法自己解决这个问题,但运气不佳。

编程语言是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];
}

你的copy/paste让你失望了,你需要修正你的setDirections,你只设置左边,当你想设置其他方向时。