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
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"
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" 

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

float zoomScale=1.0;

UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
} else {

BOOL isNew;

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

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

    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.zoomScale = zoomScale;
    innerScroll.delegate = self;
    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

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


[self.view addSubview:_theScrollView];


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?