I have a horizontal scroll filled with UIImageViews .
I want to detect a rollback on a UIImageView and change its background color.
Somehow, the gesture of pressing does not work or so.
However, when I add a scrollview binding gesture, it works. scrollview.background color can be changed.
But I want to discover the answer to the UIImageViews that it contains!
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, 768, 127)]; [scrollView setScrollEnabled:YES]; scrollView.backgroundColor = [UIColor orangeColor]; [scrollView setShowsHorizontalScrollIndicator:NO]; UIImageView *contentOfScrollView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 1, 1130, 125)]; scrollView.contentSize = CGSizeMake(contentOfScrollView.frame.size.width, contentOfScrollView.frame.size.height); for (int aantal=0; aantal < 6; aantal++) { UIImageView *item = [[UIImageView alloc] initWithFrame:CGRectMake(3+(aantal*188), 0, 185, 125)]; item.backgroundColor = [UIColor yellowColor]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:item action:@selector(imageTapped:)]; tap.numberOfTapsRequired = 1; tap.cancelsTouchesInView=YES; item.userInteractionEnabled = YES; [item addGestureRecognizer:tap]; [contentOfScrollView addSubview:item]; }
And this is the imageTapped function.
-(void)imageTapped:(UITapGestureRecognizer *)gesture { NSLog(@"tapped!"); gesture.view.backgroundColor = [UIColor whiteColor]; }
source share