首先,我将UISwipeGestureRecognizer附加到图像视图中,无法触发操作方法。然后我附上UISwipeGestureRecognizer来查看控制器的视图,它运行良好。我不知道为什么。 这是不起作用的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)];
swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
//imageView is an outlet of image view
[imageView addGestureRecognizer:swipeRight];
}
这里的代码运作良好
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)];
swipeRight.direction=UISwipeGestureRecognizerDirectionRight;
//imageView is an outlet of image view
[self.view addGestureRecognizer:swipeRight];
}
答案 0 :(得分:25)
将此代码添加到imageView:
imageView.userInteractionEnabled = YES;
答案 1 :(得分:2)
试试这个
[imageView setUserInteractionEnabled:YES];