UISwipeGestureRecognizer工作方向错误

时间:2013-03-29 08:52:14

标签: ios cocoa-touch

我向图像视图添加了4个UISwipeGestureRecognizer。但是当我向右滑动时,UISwipeGestureRecognizer被触发。当我向左滑动时,没有触发UISwipeGestureRecognizer。当我向上滑动时,左UISwipeGestureRecognizer被触发。当我向下滑动时,向下UISwipeGestureRecognizer是触发。 这是我的代码

    - (void)viewDidLoad
{
    [super viewDidLoad];
    //imageView is an outlet of image view
    imageView.userInteractionEnabled=YES;
    UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)];
    swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
    [imageView addGestureRecognizer:swipeRight];

    UISwipeGestureRecognizer *swipeLeft=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction)];
    swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
    [imageView addGestureRecognizer:swipeLeft];

    UISwipeGestureRecognizer *swipeUp=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpAction)];
    swipeLeft.direction=UISwipeGestureRecognizerDirectionUp;
    [imageView addGestureRecognizer:swipeUp];

    UISwipeGestureRecognizer *swipeDown=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDownAction)];
    swipeDown.direction=UISwipeGestureRecognizerDirectionDown;
    [imageView addGestureRecognizer:swipeDown];
}

- (void)swipeRightAction
{
    NSLog(@"swipe right");

}

- (void)swipeLeftAction
{
    NSLog(@"swipe left");

}

-(void)swipeUpAction
{

    NSLog(@"swipe up ");
}

-(void)swipeDownAction
{

    NSLog(@"swipe down ");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
        (interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
        return YES;
    return NO;
}

1 个答案:

答案 0 :(得分:1)

你这里有一个错字:

UISwipeGestureRecognizer *swipeUp=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpAction)];
// HERE
swipeLeft.direction=UISwipeGestureRecognizerDirectionUp;
[imageView addGestureRecognizer:swipeUp];

应该是swipeUp而不是swipeLeft。