我在图像视图中添加了 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;
}