0

画像ビューに 4 つの 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;
}
4

1 に答える 1

1

ここにタイプミスがあります:

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

swipeLeft ではなく swipeUp にする必要があります。

于 2013-03-29T08:54:04.610 に答える