简体   繁体   English

如何使 TextView 的滚动条在 Swift 中始终可见

[英]How to make scrollbar of TextView always visible in Swift

I use TextView in Collection View Cell.我在 Collection View Cell 中使用 TextView。 I want TextView always show scroll indicator when its content can be scrollable.我希望 TextView 在其内容可以滚动时始终显示滚动指示器。 I use this method below.我在下面使用这种方法。 But It shows only first after that it disappear.但它只显示在它消失之后。 How to make scroll indicator of TextView always show?如何让TextView的滚动指示器一直显示?

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

Currently no public apis available for that.目前没有可用的公共 api。 Someone have solution that using timer.有人有使用计时器的解决方案 But I'd prefer flashing indicator once when view did appeared.但我更喜欢在视图出现时闪烁一次指示器。

Another idea is making textview contents to scroll to top, so that the user can understand there is content to scroll.另一个想法是使 textview 内容滚动到顶部,以便用户可以理解有内容要滚动。 Below code copied .下面的代码复制

textView.setContentOffset(.zero, animated: true)

flashScrollIndicators: It will flash only once when your textView is created or page is loaded. flashScrollIndicators:它只会在创建 textView 或加载页面时闪烁一次。

Set flashScrollIndicators on regular intervals:定期设置 flashScrollIndicators:

let timerTask = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(refreshFlashIndicator), userInfo: nil, repeats: true)

@objc func refreshCrawlerStatus() {
   self.descriptionTextView.flashScrollIndicators()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM