Подтвердить что ты не робот

Распознаватель жестов не работает на subview

Сначала я прикрепляю 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];
}
4b9b3361

Ответ 1

Добавьте этот код в изображение:

imageView.userInteractionEnabled = YES;

Ответ 2

Попробуйте это [imageView setUserInteractionEnabled:YES];