的UIScrollView滚动

的UIScrollView滚动

问题描述:

我使用这种方法向下滚动一个UIScrollView:的UIScrollView滚动

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

的一点是,如果在UIsecollView含量大于滚动视图,一切工作正常的实际尺寸更大,但在其他方面,如果我有较少的内容,此方法隐藏滚动视图的一切。我怎样才能阻止呢?

为什么你会滚动它,如果它太矮了,滚动?取而代之的是,请检查内容大小比滚动视图尺寸高:

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 
} 

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