使用setcontentsize调整UIScrollView的大小

时间:2013-04-22 23:31:01

标签: ios objective-c uiscrollview uikit

我正在尝试在UICOllectionViewCell中调整UIScrollView的大小,但它没有调整它的大小。

-(int)resizeScrollView:(int)height{

    NSLog(@"Before Scroll height %f",self.scrollView.frame.size.height);
    float currentHeight=self.scrollView.frame.size.height+height+200;
    NSLog(@"height %f",currentHeight);
    CGSize size=CGSizeMake(self.scrollView.frame.size.width ,
                           currentHeight + 10 );
    [self.scrollView setContentSize:size];    
    self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    NSLog(@"After Scroll height %f",self.scrollView.frame.size.height);

    return currentHeight;
}

1 个答案:

答案 0 :(得分:0)

设置contentSize可调整滚动视图滚动的逻辑空间量。您需要设置framebounds以在其父视图中调整滚动视图的大小。

CGRect scrollFrame = self.scrollView.frame;
scrollFrame.size.height += height + 210;
self.scrollView.frame = scrollFrame;