【问题标题】:UIScrollView Scrolling UpUIScrollView 向上滚动
【发布时间】:2017-08-24 22:54:40
【问题描述】:

我正在尝试让 UIScrollView 向上滚动而不是向下滚动。我已经设置了所有内容,但我不知道应该使用哪条线来完成此操作。我该怎么办?

尼尔

【问题讨论】:

    标签: ios swift xcode


    【解决方案1】:

    我认为你的意思是你想要一个从底部开始的scrollView,并且你的内容可以通过向上滚动来访问。

    在这种情况下,您只需要弄清楚您的内容有多大,并将您的scrollViewsetContentOffset 设置为您的内容的高度:

    override func viewDidLoad() {
        // other code here...
    
        // set the contentSize of the scrollView somewhere in here...
    
        // get the offset based on the size of the content
        let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
        // do not animate because we want to immediately scroll to the bottom
        scrollView.setContentOffset(bottomOffset, animated: false)
    

    此代码改编自this answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-11
      • 2014-01-02
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多