Я не следующий код, который добавляет UITapGestureRecognizer к UIImageView:UIImageView GestureRecognizer Не Рабочая
UIImageView *circleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_circle"]];
[circleView setUserInteractionEnabled:YES];
[circleView setFrame:CGRectMake(20 + 60 * ([self.tasks count] - 1), self.bounds.size.height - 300, 44, 44)];
// register gestures
[self registerGestureRecognizer:circleView];
[self addSubview:circleView];
-(void) registerGestureRecognizer:(UIImageView *) circleView
{
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
tapGestureRecognizer.delegate = self;
[circleView addGestureRecognizer:tapGestureRecognizer];
}
-(void) tapped:(UITapGestureRecognizer *) recognizer
{
NSLog(@"tapped!");
}
Но когда я прикасаюсь изображение просверленных метод не вызывается! Я что-то упускаю.
В UIScrollView добавлен вид, содержащий UIImageView.
UPDATE: Вот код, который добавляет TaskView в UIScrollView
-(TaskView *) createTaskView
{
TaskView *taskView = [[TaskView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
taskView.userInteractionEnabled = YES;
taskView.backgroundColor = [UIColor clearColor];
[taskView.textView setDelegate:self];
return taskView;
}
-(void) initializeScrollViewWithTasks
{
for(int day = 1; day <= 7; day++)
{
TaskView *taskView = [self createTaskView];
taskView.tag = day;
// [_taskViews addObject:taskView];
[self.scrollView addSubview:taskView];
}
}
РЕШЕНИЕ:
Полностью моя вина! Я делал что-то безумное, добавляя элементы в UIScrollView. Починил это!
Работает отлично для меня. Возможно, вам нужно включить взаимодействие с пользователем на 'self' и, возможно, наблюдать за цепочкой. – Kevin
UIImageView содержится внутри UIView, а UIView добавляется в UIScrollView. –
circleView.userInteractionEnabled = YES; и убедитесь, что нет изображения UIView для просмотра изображений, которые перехватывают события нажатия –