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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:09:11+00:00 2026-06-10T15:09:11+00:00

After having spent half the night trying to get this to work on my

  • 0

After having spent half the night trying to get this to work on my own I finally turn to StackWisdom:

I’m trying to implement a horizontal, paging UIScrollView with a sort of parallax scrolling background image (similar to the UI on Windows Phone 7). I’ve managed to get the scrolling working just fine using scrollViewDidScroll. For a 3 page example I am using an image with 1460×480/2920×960 pixels (3*320 points + 2*250 padding for width). And depending on the factor I use in scrollViewDidScroll, the right edge of the scroll view works just fine as well.

However, when on page 1 and trying to scroll further left, it becomes visible that the background image ends at the border of the screen and the window’s (grey, white, whatever) background becomes visible. How do I configure the scroll view so that there’s an extra, say, 250 pixels of the background image to the left of the content area? I’ve tried insets, offsets, repositioning the content area and countless combinations thereof, but to no avail.

Also, it’s 5:30 in the morning here and I’m tired. -_-

Source:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    CGRect screenRect = [[self window] bounds];

    // Create and configure scroll view
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
    [scrollView setDelegate:self];
    [scrollView setPagingEnabled:YES];
    [scrollView setShowsHorizontalScrollIndicator:NO];

    [[self window] addSubview:scrollView];

    pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];
    [pageControl setNumberOfPages:3];
    [pageControl setCurrentPage:0];
    [pageControl setBackgroundColor:[UIColor clearColor]];
    [[self window] addSubview:pageControl];

    backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"desert_panorama_cropped.png"]];
    [scrollView addSubview:backgroundImageView];

    // Create first content view
    screenRect.origin.x = 0;
    ContentView *firstContentView = [[ContentView alloc] initWithFrame:screenRect string:@"Page 1"];
    [scrollView addSubview:firstContentView];

    // Create second content view
    screenRect.origin.x = screenRect.size.width;
    ContentView *secondContentView = [[ContentView alloc] initWithFrame:screenRect string:@"Page 2"];
    [scrollView addSubview:secondContentView];

    // Create third content view
    screenRect.origin.x = screenRect.size.width * 2.0;
    ContentView *thirdContentView = [[ContentView alloc] initWithFrame:screenRect string:@"Page 3"];
    [scrollView addSubview:thirdContentView];

    CGRect contentRect = screenRect;
    contentRect.size.width *= 3.0;
    [scrollView setContentSize:contentRect.size];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float x = scrollView.contentOffset.x;
    NSLog(@"Scrollview did scroll to offset: %f", x);

    CGRect backgroundImageFrame = backgroundImageView.frame;
    backgroundImageFrame.origin.x = x/1.5;
    backgroundImageView.frame = backgroundImageFrame;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int newOffset = scrollView.contentOffset.x;
    int newPage = (int)((newOffset)/(scrollView.frame.size.width));
    [pageControl setCurrentPage:newPage];
}

Any help would be much appreciated.

  • 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-10T15:09:13+00:00Added an answer on June 10, 2026 at 3:09 pm

    I think all you have to do is add a constant to this line like so:

    backgroundImageFrame.origin.x = x/1.5 - 250;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get back into rails after a while and am having a
I'm having a really difficult time trying to get this app loaded to the
I'm desperate having spent well over an hour trying to troubleshoot this. I am
after having spent few months in trying to master the syntax and rules, I
After having this issue on our websites over secure SSL connections for Office file
I've spent two days on this and have gotten nowhere. I'm trying to use
After having checked extensively for an answer to this question, I still cannot find
I feel embarrassed asking this question, but I've spent the last half an hour
After having spent two days attempting to rasterize jpeg's from SVG strings using ImageMagick
(Sorry if this is a dupe) I've just spent a long time trying to

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.