Ответ 1
Добавьте этот код в изображение:
imageView.userInteractionEnabled = YES;
Сначала я прикрепляю 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];
}
Добавьте этот код в изображение:
imageView.userInteractionEnabled = YES;
Попробуйте это
[imageView setUserInteractionEnabled:YES];