Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8884251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:01:13+00:00 2026-06-14T21:01:13+00:00

I have a horizontal scrollview filled with UIImageViews . I want to detect a

  • 0

I have a horizontal scrollview filled with UIImageViews.

I want to detect a tap on the UIImageView and have its background color changed.

Somehow the tap gesture is not working or so.

However, when I add a tap gesture to the scrollview, it works. The scrollview.background color can be changed.

But I want to detect a tap on the UIImageViews 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];
}

//UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
//[scrollView addGestureRecognizer:tap];
scrollView.userInteractionEnabled=YES;
scrollView.delaysContentTouches=NO;
[scrollView addSubview:contentOfScrollView];
[self.view addSubview:scrollView];

And this is the imageTapped function.

-(void)imageTapped:(UITapGestureRecognizer *)gesture
{
    NSLog(@"tapped!");
    gesture.view.backgroundColor = [UIColor whiteColor];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:01:14+00:00Added an answer on June 14, 2026 at 9:01 pm

    User interaction is set to NO by default for UIImageView, so you need to set it to YES.
    You set it to yes for “item”, but not for contentOfScrollView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI! I have a surfaceView inside a horizontal scrollview that I want to fill
I have a horizontal scrollView which contains 2 images.The scrollView is circular.What I want
I have horizontal scrollView in it views(Buttons) are added dynamically. What I want is
I have a horizontal scrollview in my app. On either side of the scrollview,
I have a horizontal ScrollView implemented and working. however, when I Scrol horizontally he
I have a horizontal unordered list I want to center horizontally in a div
I have a horizontal list (for a nav bar) and i want an individual
I want to use the scrollview as something like a picker in horizontal mode.
In my application I have to implement the functionality of the horizontal scrollview. I
I have a horizontal UIScrollview set up (meaning its not one that scrolls up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.