Nested UIScrollView's for paging

I am trying to implement a paging solution using nested UIScrollView's and have an annoying problem which am finding troublesome to resolve.

The view loads up just fine but as soon as the user initiates a scroll the view pops off the top by about 20 pixels and will bounce back to that position when pulled down.

I have followed the guidelines in other answered questions but can't seem to nail what the problem is.

When I use the innerScroll on its own, vertical works just fine. Soon as I nest it, the problem occurs.

I've tried to increase the contentSize height to be more than the height of the content as I guessed that would be the issue but doesn't seem to make a difference.

CGRect screenSize = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);

_theScrollView=[[customScrollView alloc] initWithFrame:screenSize];
_theScrollView.pagingEnabled = YES;
_theScrollView.directionalLockEnabled = YES;
_theScrollView.bounces = NO;

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                                           target:self
                                                                           action:@selector(performAction:)];
NSArray* buttons = [[NSArray alloc]initWithObjects:barButton, nil];

CGSize scrollViewContentSize = screenSize.size;
scrollViewContentSize.width = screenSize.size.width * self.thisform.formPages.count;
scrollViewContentSize.height = self.view.bounds.size.height;
_theScrollView.contentSize = scrollViewContentSize;

self.actionButton = barButton;
self.picVisible = NO;

self.navigationItem.rightBarButtonItems = buttons;

UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(onCancelButtonSelected:)];
self.navigationItem.leftBarButtonItem = backButton;

[self.view setUserInteractionEnabled:YES];

self.views = [[NSMutableArray alloc] initWithCapacity:_thisform.formPages.count];

int i = 0;
NSSortDescriptor *byPage = [[NSSortDescriptor alloc] initWithKey:@"formPageNumber" 
                                                       ascending:YES];

NSArray *sortedPages = [self.thisform.formPages sortedArrayUsingDescriptors:[NSArray arrayWithObjects: byPage, nil]];

float zoomScale=1.0;

UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    zoomScale=1.0;
} else {
    zoomScale=1.3;
}

BOOL isNew;

for (FormPages *page in sortedPages) {
    NSData *formImage = page.formPage;

    //innerScroll
    UIImage *image = [UIImage imageWithData:formImage];
    Imager *imageView = [[Imager alloc] initWithImage:image];
    [imageView setUserInteractionEnabled:YES];
    imageView.tag = page.formPageNumber;
    imageView.fieldCollection = [Utility populateFormFields:self.thisform 
                                                 pagenumber:page.formPageNumber];

    CGRect frame = CGRectMake(_theScrollView.bounds.size.width * i, 0, _theScrollView.bounds.size.width, _theScrollView.bounds.size.height);

    float contentWidth = _theScrollView.bounds.size.width;
    float contentHeight = imageView.frame.size.height;

    CGSize contentSize = CGSizeMake (contentWidth,contentHeight);

    TPKeyboardAvoidingScrollView *innerScroll = [[TPKeyboardAvoidingScrollView alloc] initWithFrame:frame];

    innerScroll.contentSize = contentSize;
    [innerScroll setUserInteractionEnabled:YES];
    innerScroll.minimumZoomScale=1;
    innerScroll.zoomScale = zoomScale;
    innerScroll.maximumZoomScale=2.5;
    innerScroll.delegate = self;
    innerScroll.scrollsToTop=NO;
    innerScroll.currentView = imageView;

    imageView.frame = screenSize;

    CGSize pageSize = [Utility GetPageSize:self.thisform];

    float viewWidth = imageView.frame.size.width;
    float formWidth = pageSize.width;
    float viewHeight = imageView.frame.size.height;
    float formHeight = pageSize.height;

    float widthRatio = viewWidth / formWidth;
    float heightRatio = viewHeight / formHeight;

    [self populateControls:NO
                      view:imageView
                widthRatio:widthRatio
               heightRatio:heightRatio];

    [innerScroll addSubview:imageView];
    [_theScrollView addSubview:innerScroll];
    [self.views addObject:innerScroll];

    i++;
}

[self.view addSubview:_theScrollView];

Answers


In IOS7 translucent property of the UINavigationBar is set to YES by default rather than NO as in previous IOS versions as answered in previous question.

View got hidden below UINavigationBar iOS 7


Need Your Help

zend framework / view <?= does not work ? why?

php view php-ini short-open-tags

Strange.. with my installation of the Zend Framework

Can't Set Default in Twitter Bootstrap Toggleable Tab

javascript tabs twitter-bootstrap nav

The tabs work nicely when clicked but selecting the default tab on window load fails. The javascript runs, no errors, but nothing happens. Any ideas?