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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:37:30+00:00 2026-06-10T06:37:30+00:00

I’ve got a main View Controller that has a subview of UIScrollView and another

  • 0

I’ve got a main View Controller that has a subview of UIScrollView and another 2 UIViewControllers (each with nibs UIView and buttons). The UIViewControllers’ UIView are added into UIScrollView using addSubView method. And I’d like to put both UIViewControllers side by side.

I’ve got the following code but it doesn’t seem to work.

[self scrollView].pagingEnabled = YES;
[self scrollView].contentSize = CGSizeMake(768 * 2, 1024);
[[self scrollView] setDelegate:self];

CGRect frame1;
frame1.origin.x = 0;
frame1.origin.y = 0;
frame1.size = CGSizeMake(768, 1024);

// Model one
oneView = [[OneViewController alloc] initWithNibName:@"OneViewController" bundle:nil];
//oneView.view.frame = frame1;
[self.scrollView addSubview:oneView.view];
oneView.view.frame = frame1;

// Model two

CGRect frame2;
frame2.origin.x = 768;
frame2.origin.y = 0;
frame2.size = CGSizeMake(768, 1024);

twoView = [[TwoViewController alloc] initWithNibName:@"TwoViewController" bundle:nil];
//twoView.view.frame = frame2;
[self.scrollView addSubview:twoView.view];
twoView.view.frame = frame2;

Why does oneView and twoView inside UIScrollView are in the same place when I’ve set their frame.origin.x? twoView seems to be on top of oneView where it should be side by side? Any idea where I am doing it wrong? Thanks!

Update: Here’s my full project code on github: http://bit.ly/PLe1Le

  • 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-10T06:37:31+00:00Added an answer on June 10, 2026 at 6:37 am

    The reason why this started happening is that any UIView instance that is the value of a UIViewController‘s view property will sometimes get a message to resize its view to that of its superviews.

    Specifically, the undocumented method viewDidMoveToWindow:shouldAppearOrDisappear: will be called when a view controller’s view is added to a window, as is happening at application launch in this instance. At this time, if the view controller’s view instance is the size of the main window or larger, it will be resized to the size of its superview.

    The original code took the two views that were loaded from the the .xibs and sized them to 768 * 1024, which is the size of the window. This happens before -makeKeyAndVisible is called on the window, which ends up triggering the resize. I used KVO in the app delegate to watch the frames get resized; here is a stack trace at the time of resize:

    * thread #1: tid = 0x1f03, 0x000030f9 scroller`-[ViewController observeValueForKeyPath:ofObject:change:context:] + 105 at ViewController.m:71, stop reason = breakpoint 1.1
        frame #0: 0x000030f9 scroller`-[ViewController observeValueForKeyPath:ofObject:change:context:] + 105 at ViewController.m:71
        frame #1: 0x0093ad91 Foundation`NSKeyValueNotifyObserver + 345
        frame #2: 0x0093a895 Foundation`NSKeyValueDidChange + 438
        frame #3: 0x0092033e Foundation`-[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 131
        frame #4: 0x009cdcb4 Foundation`_NSSetRectValueAndNotify + 187
        frame #5: 0x000e1786 UIKit`-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 657
        frame #6: 0x0005310c UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 1040
        frame #7: 0x00052edb UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 479
        frame #8: 0x0005d5ab UIKit`-[UIScrollView _didMoveFromWindow:toWindow:] + 65
        frame #9: 0x00052edb UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 479
        frame #10: 0x0004f692 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 158
        frame #11: 0x0005446f UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1633
        frame #12: 0x0004e14b UIKit`-[UIView(Hierarchy) addSubview:] + 56
        frame #13: 0x0003d550 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 380
        frame #14: 0x0003d670 UIKit`-[UIWindow _setHidden:forced:] + 280
        frame #15: 0x0003d836 UIKit`-[UIWindow _orderFrontWithoutMakingKey] + 49
        frame #16: 0x0004472a UIKit`-[UIWindow makeKeyAndVisible] + 35
        frame #17: 0x00002575 scroller`-[AppDelegate application:didFinishLaunchingWithOptions:] + 661 at AppDelegate.m:21
        frame #18: 0x00015386 UIKit`-[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1292
        frame #19: 0x00016274 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 524
        frame #20: 0x00025183 UIKit`-[UIApplication handleEvent:withNewEvent:] + 1027
        frame #21: 0x00025c38 UIKit`-[UIApplication sendEvent:] + 68
        frame #22: 0x00019634 UIKit`_UIApplicationHandleEvent + 8196
        frame #23: 0x0139eef5 GraphicsServices`PurpleEventCallback + 1274
        frame #24: 0x01488195 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
        frame #25: 0x013ecff2 CoreFoundation`__CFRunLoopDoSource1 + 146
        frame #26: 0x013eb8da CoreFoundation`__CFRunLoopRun + 2218
        frame #27: 0x013ead84 CoreFoundation`CFRunLoopRunSpecific + 212
        frame #28: 0x013eac9b CoreFoundation`CFRunLoopRunInMode + 123
        frame #29: 0x00015c65 UIKit`-[UIApplication _run] + 576
        frame #30: 0x00017626 UIKit`UIApplicationMain + 1163
        frame #31: 0x000022ad scroller`main + 141 at main.m:16
    

    We can verify that this happens because the content views are a UIViewController ‘s view instance by instantiating a view and adding it the scroll view at the same time. I added the following code to the end of ViewController ‘s viewDidLoad implementation:

    CGRect frame3 = frame2;
    frame3.origin.x = 768.0f * 2.0f;
    UIView *thirdView = [[UIView alloc] initWithFrame:frame3];
    [thirdView setBackgroundColor:[UIColor redColor]];
    [self.scrollView addSubview:thirdView];
    

    As well as changing the line assigning content size to:

    [self scrollView].contentSize = CGSizeMake(768 * 3, 1024);
    

    This view does not get its frame set during makeKeyAndVisible and is in the correct place.

    To work around the issue, I’d recommend setting up the view hierarchy after the window has -makeKeyAndVisible called, possibly in a viewWillAppear (Not sure if that will have the same issue) or by otherwise structuring your code to delay the laying out of the scroll view. Alternatively, re-set the frames at a later time as an explicit undoing of this bug.

    I hope this helps explain what was happening and that the evidence I provide is clear and credible; it seems you already have a fix for your particular case but hopefully this answer stands as a general solution to frame misbehavior when UIViewController‘s have their views laid out inside scroll views.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a

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.