Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Screen UIScrollView not working Correctly

I have an application like the photos app where the main view is a UIScrollView which takes up the full size of the screen. Also, like the photos app, when the user taps the screen there are translucent navigation, status, and tool bars which reappear / disappear.

I am having a problem setting the UIViewControllers main view as a UIScrollView and having it take up the full length of the screen. The problem is that when the navigation and status bars are shown, the UIScrollView gets pushed down by the height of the navigation and status bars (it doesn't go underneath them like it's suppose to). When the user taps the screen and the navigation / status bars disappear, then it resets itself to take up the full length of the screen like it's suppose to.

A simple work around of setting the main view as a UIView and attaching a UIScrollView on top of it works. However, I'd like to try and get this to work without any workarounds (ie adjusting the UIScrollViews contentInset, etc) because in theory it should work.

Below is the code I'm implementing:

- (void)loadView
{

    self.wantsFullScreenLayout = YES;

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0,0,320,480)];
    scrollView.contentSize = CGSizeMake(320, 480);
    scrollView.scrollEnabled = NO;
    scrollView.contentOffset = CGPointZero;
    scrollView.bounces = NO;
    self.view = scrollView;
    [scrollView release];

}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.navigationController.navigationBar.translucent = YES;
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent animated: NO];
    self.navigationController.toolbarHidden = NO;
    self.navigationController.toolbar.barStyle = UIBarStyleBlack;
    self.navigationController.toolbar.translucent = YES;

    [self startTimer];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    self.navigationController.navigationBar.translucent = NO;
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: NO];

    [self cancelTimer];
}

UPDATE: I've noticed it's the contentOffset and contentInset that are changing, not the scrollViews frame. When the bars have disappeared and the UIScrollView is the full size of the screen (as it should be), the contentOffset and contentInset are as follows:

Content Offset: {0, -20}
Content Inset: {20, 0, 44, 0}

When the bars are visible and the UIScrollView is pushed down, the contentOffset and contentInset are as follows:

Content Offset: {0, -64}
Content Inset: {64, 0, 44, 0}
like image 738
Ser Pounce Avatar asked Jun 05 '12 19:06

Ser Pounce


2 Answers

I solved a similar issue on iOS7 after reading Apple's UI Transition Guide: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

It turns out UIViewController has a automaticallyAdjustsScrollViewInsets boolean property. Default is true, disabling this made my UIScrollView fill up the entire window, instead of being pushed down.

like image 152
Ronald Avatar answered Oct 05 '22 22:10

Ronald


I spoke with DTS about this and they said this is the designed behavior and recommended to attach the UIScrollView to a parent UIView.

like image 31
Ser Pounce Avatar answered Oct 05 '22 22:10

Ser Pounce