Search code examples
iphonexcodeuiscrollviewscrollviewresolution

UIScrollView start another position


I have project is single view app and add to view controller scrollview with parameters

[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(0, 960)];

if screen resolution is 320x480 then we have some invisible "screen 2" (320x480) how do I make that - did load app at position "screen 2" and after that I can scroll not down, but to up at start launch app.

for example

How to release that?


Solution

  • you have to give the scrollview a proper content size, depending on the screen size.

    Assuming that the scrollview is fullscreen in portrait:

    //------------------------------------------
    - (void)viewDidLoad{
      [super viewDidLoad];
    
      CGRect screenSize = [[UIScreen mainScreen] bounds];
    
      [scroller setScrollEnabled:YES];
      [scroller setContentSize:CGSizeMake(0, screenSize.size.height)];
    
    }
    
    //------------------------------------------
    
    - (void)viewDidAppear:(BOOL)animated{
      [super viewDidAppear:animated];
    
      CGRect screenSize = [[UIScreen mainScreen] bounds];
    
      CGPoint scrollPoint = CGPointMake( 0.0, screenSize.size.height / 2);
    
      [scroller setContentOffset:scrollPoint animated:YES];
    
    }