2013-03-29 37 views
0

我加4 UISwipeGestureRecognizer到圖像時,我向右滑動,向上UISwipeGestureRecognizer是triggered.When我向左滑動view.but,沒有UISwipeGestureRecognizer是triggered.When我刷卡了,留下UISwipeGestureRecognizer是triggered.When我刷卡向下,向下,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

您在這裏有一個錯字:

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

應該swipeUp而不是swipeLeft。

+0

效果很好,非常感謝。 –

+0

我很高興它幫助你 –

相關問題