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

  • Home
  • SEARCH
  • 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 8068427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:40:58+00:00 2026-06-05T12:40:58+00:00

UPDATE It turns out that the code below is not actually the problem. In

  • 0

UPDATE

It turns out that the code below is not actually the problem. In my app delegate I am doing:

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

    self.window.rootViewController = self.viewController;// <-- this does not work
    //[self.window addSubview:self.viewController.view]; // <-- this works

    [self.window makeKeyAndVisible];
    return YES;
}

If I remove the statement “self.window.rootViewController = self.viewController” and just add the viewController’s view to the window, it works. Can anyone explain this? Does setting the rootViewController on the window constrain the child’s bounds? I have tried to go through the docs, but it doesn’t mention much about this.

ORIGINAL POST

I am having trouble adding padding to pages in a UIScrollView. I am basically trying to setup a simple scroll view that shows UIViews in different pages separated by a predefined padding (kind of like the Photos app without photos). I have been trying to follow Apple’s ScrollView example from WWDC 2010 and their sample app PhotoScroller but always come up with padding showing in the view. The app currently hides the status bar and adds 1 view controller to the window. To make things simple, each of the pages should show a UIView that is colored green, while the space where there is padding is yellow. You should only see the yellow when the user is scrolling. Here are the first 3 pages:

pages 1, 2, and 3

I have a single class level field called pagingScrollView declared in the .h file. In my single view controller, I am basically just trying to follow what the sample code is doing.

#define PADDING  10
#define PAGE_COUNT 3

- (void)loadView
{
    CGRect pagingScrollFrame = [[UIScreen mainScreen] bounds];
    pagingScrollFrame.origin.x -= PADDING;
    pagingScrollFrame.size.width += (2 * PADDING);
    pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollFrame];

    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor yellowColor];
    pagingScrollView.contentSize = CGSizeMake(pagingScrollFrame.size.width * PAGE_COUNT, pagingScrollFrame.size.height);

    self.view = pagingScrollView;

    for(int i = 0; i < PAGE_COUNT; i++) {
        CGRect frame = [self frameForPageAtIndex:i];
        UIView *page = [[UIView alloc] initWithFrame:frame];
        page.backgroundColor = [UIColor greenColor];
        [pagingScrollView addSubview:page];
    }
}

- (CGRect)frameForPageAtIndex:(NSUInteger)index {
    CGRect bounds = pagingScrollView.bounds;
    CGRect pageFrame = bounds;

    pageFrame.size.width -= (2 * PADDING);
    pageFrame.origin.x = (bounds.size.width * index) + PADDING;

    return pageFrame;
}

The pagingScrollFrame has a width of 340, so (I thought) that scroll view would be broken up into pages of 340 pixels. What am I missing?

  • 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-05T12:41:01+00:00Added an answer on June 5, 2026 at 12:41 pm

    The reason the paging is off is because setting the RootViewController on the window is apparently doing something behind the scenes (what that is, I don’t know). To fix is, I use the old way of adding a view to the window.

    [self.window addSubview:self.viewController.view];
    

    If you think you know how to fix it while setting the RootViewController, please let me know!

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

Sidebar

Related Questions

Update Turns out the error was in the crypto processor code, that is fixed.
Update : Alright, it turns out the reason that the below isn't working is
UPDATE: As it turns out, the below is caused by a caching issue on
Final Update : Turns out the fix to this problem is a depressing one.
Update: Turns out that this is a duplicate of: JSLint: Using a function before
Update: Turns out this is undocumented behaviour of the NetStream class - NetStream loads
(update) ICustomTypeDescriptor works for my Windows Forms app, but not for Silverlight; Not supported.
The code below has (at least) two problems: the Copy button doesn't update the
When I try to run the code below the browser does not display an
I'm having problems finding out what's wrong with the code below. I have consulted

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.