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 766609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:04:30+00:00 2026-05-14T17:04:30+00:00

I have a scrollView (width:320px height:100px) on my UIView, inside it I add 10

  • 0

I have a scrollView (width:320px height:100px) on my UIView, inside it I add 10 images with width:106.5px each. After that I use this function to have 3 different parts inside my scrollView, so everytime I scroll, an image will automatically be center.


-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

    [self returnToPosition:self.scrollView];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    [self returnToPosition:self.scrollView];
}

-(void)returnToPosition:(UIScrollView *)scrollView {

    CGFloat itemWidth = 106.5f;
    CGFloat position = [self.scrollView contentOffset].x;
    CGFloat newPosition = 0.0f;
    CGFloat offSet = position / itemWidth;
    NSUInteger target = (NSUInteger)(offSet + 0.5f);

    newPosition = target * itemWidth;

    [self.scrollView setContentOffset:CGPointMake(newPosition, 0.0f) animated:YES];

}

Here is my question, I want to be able to know which image will be in the middle position after the user scroll the View, because I want to display on my UIView a text, specific to that image. But I don’t know how to do that.

Some Ideas?

  • 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-05-14T17:04:31+00:00Added an answer on May 14, 2026 at 5:04 pm

    Well, I am not going to paste in a lot of code here, but this is how I do that:
    I keep a spatial index (rtree) where I insert all my objects. It is much faster to obtain list of items intersecting with a given one.
    I have a class that is also my scrollview’s delegate. And every time scrollViewDidScroll: gets called I obtain visibleRect of the my content view, then using rtree index quickly locate items that are in the rect, and draw accordingly.

    You would only have to decide which image is “in the middle” in case yours are small, and there might be 4 fitting in the visible rectangle of the scroll view.

    Hope that helps,
    Robert

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

Sidebar

Related Questions

I have created a UIScrollView (canvas.scrollview) and have a custom UIView (canvas) inside it.
I have a VideoView that is inside a scrollView. When I scroll the scrollView,
I have 5 pictures inside an infinite scrollView. So in order to make that
I have a UIScrollView which I create and size dynamically using... scrollView.contentSize = CGSizeMake(scrollView.frame.size.width
I have an app which contains a scrollview with several tableviews. Each tableview is
I am trying to create a UIScrollView programatically. I have a scrollView for that
I have a scrollview that automatically generates a series of subviews containing imageviews. The
I have a UIScrollView subclass that I am programmatically scrolling using UIView animations. I'd
I have a horizontal scrollView which contains 2 images.The scrollView is circular.What I want
So I have a UIViewController subclass called MyTabBarViewController that has a UIScrollView. Inside of

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.