2015-09-10 95 views
0

我試圖自動設置我的UIScrollView的ContentSize,但是當我這樣做時,框架 uiscrollview的高度與screenHeight不一樣,因爲我想。UIScrollView自動ContentSize

有我的代碼:

-(void) viewWillAppear:(BOOL)animated { 
     [self.scrollGeral setTranslatesAutoresizingMaskIntoConstraints:YES]; 

     [self.scrollGeral setContentSize:(CGSizeMake(screenSize.size.width, [self calcularAlturaScrollView]))]; 
} 



-(CGFloat) calcularAlturaScrollView { 
    CGFloat scrollViewHeight = 0.0f; 
    for (UIView* view in self.scrollGeral.subviews) 
    { 
     scrollViewHeight += view.frame.size.height; 
    } 
    return scrollViewHeight; 
} 

因此,I'have試圖包含以下行:

[self.scrollGeral setFrame:CGRectMake(0, 0, screenSize.size.width, screenSize.size.height)]; 

但如果我這樣做,在UIScrollView的 '禁用' 滾動

回答

0

我用下面的代碼解決了我的問題:

-(void) viewDidLayoutSubviews { 
    [self.scrollGeral setContentSize:(CGSizeMake(screenSize.size.width, [self calcularAlturaScrollView]))]; 
} 
相關問題