嵌套的UIScrollView用于分页

时间:2014-01-08 10:15:54

标签: ios objective-c cocoa-touch uiscrollview

我正在尝试使用嵌套的UIScrollView来实现分页解决方案,并且遇到一个令人烦恼的问题,这个问题很难解决。

视图加载得很好但是一旦用户启动滚动,视图就会从顶部弹出约20个像素,并在拉下时弹回到该位置。

我在其他已回答的问题中遵循了指南,但似乎无法解决问题所在。

当我自己使用innerScroll时,垂直工作正常 我窝的时候就会出现问题。

我已经尝试将contentSize高度增加到超过内容的高度,因为我猜这将是问题,但似乎没有什么区别。

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];

1 个答案:

答案 0 :(得分:0)

在IOS7中,UINavigationBar的半透明属性默认设置为YES,而不是之前IOS版本中的NO,如上一个问题所述。

View got hidden below UINavigationBar iOS 7