2013-02-14 117 views
1

我使用這種方法向下滾動一個UIScrollView:的UIScrollView滾動

CGPoint bottomOffset = CGPointMake(0, self.ScrollForComments.contentSize.height -  self.ScrollForComments.bounds.size.height); 
[self.ScrollForComments setContentOffset:bottomOffset animated:YES]; 

的一點是,如果在UIsecollView含量大於滾動視圖,一切工作正常的實際尺寸更大,但在其他方面,如果我有較少的內容,此方法隱藏滾動視圖的一切。我怎樣才能阻止呢?

回答

1

爲什麼你會滾動它,如果它太矮了,滾動?取而代之的是,請檢查內容大小比滾動視圖尺寸高:

if (self.ScrollForComments.contentSize.height > self.ScrollForComments.bounds.size.height) { 
    // if it is, run your code 
    CGPoint bottomOffset = CGPointMake(0, self.ScrollForComments.contentSize.height - self.ScrollForComments.bounds.size.height); 
    [self.ScrollForComments setContentOffset:bottomOffset animated:YES]; 
} else { 
    // if it is not, either do nothing or scroll to the top 
} 
0

你可能想檢查self.ScrollForComments.contentSize.height - self.ScrollForComments.bounds.size.height > 0如果不是不叫setContentOffset