【问题标题】:How to make scrollbar of TextView always visible in Swift如何使 TextView 的滚动条在 Swift 中始终可见
【发布时间】:2020-01-21 08:56:43
【问题描述】:

我在 Collection View Cell 中使用 TextView。我希望 TextView 在其内容可滚动时始终显示滚动指示器。我在下面使用这种方法。但它只首先显示,然后消失。如何让TextView的滚动指示器一直显示?

override func draw(_ rect: CGRect) {
        super.draw(rect)
        self.descriptionTextView.flashScrollIndicators()
    }

【问题讨论】:

标签: ios swift mobile


【解决方案1】:

目前没有可用的公共 api。有人有solution 使用计时器。但我更喜欢在视图出现时闪烁​​一次。

另一个想法是让 textview 的内容滚动到顶部,以便用户可以理解有要滚动的内容。下面的代码copied

textView.setContentOffset(.zero, animated: true)

【讨论】:

    【解决方案2】:

    flashScrollIndicators: 当你的textView被创建或者页面被加载时它只会闪烁一次。

    定期设置 flashScrollIndicators:

    let timerTask = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(refreshFlashIndicator), userInfo: nil, repeats: true)
    
    @objc func refreshCrawlerStatus() {
       self.descriptionTextView.flashScrollIndicators()
    }
    

    【讨论】:

      猜你喜欢
      • 2023-02-01
      • 2021-06-20
      • 2018-05-22
      • 2013-10-19
      • 2010-11-15
      • 2021-02-15
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      相关资源
      最近更新 更多