ios - UIScrollView 向下滚动

标签 ios xcode uiscrollview

我正在使用此方法向下滚动 UIscrollView:

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

要点是,如果 UIsecollView 中的内容大于 ScrollView 的实际大小,则一切正常,但如果内容较少,则此方法会隐藏 ScrollView 中的所有内容。我怎样才能阻止这个?

最佳答案

如果它太短而无法滚动,为什么要滚动它?相反,检查内容大小是否高于 ScrollView 大小:

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
}

关于ios - UIScrollView 向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14880770/

相关文章:

ios - 当另一个 UIScrollView 滚动时停止动画 UIScrollView

ios - ScrollView 区域

javascript - 排毒问题 : BUILD FAILED Ld build/Build/Products/Debug-iphonesimulator

ios - 在 xib 中为界面生成器创建一个圆圈

ios - 新版本如何防止核心数据问题

ios - 是否有用于解析的 CocoaPods 库?

ios - 如何使 UIScrollView 的 subview 居中

iPhone手势/事件类似于Flash中的鼠标输入

ios - 将NSString转换为NSDate

xcode - Swift 3 中的隐藏按钮