簡體   English   中英

如何使 TextView 的滾動條在 Swift 中始終可見

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

我在 Collection View Cell 中使用 TextView。 我希望 TextView 在其內容可以滾動時始終顯示滾動指示器。 我在下面使用這種方法。 但它只顯示在它消失之后。 如何讓TextView的滾動指示器一直顯示?

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

目前沒有可用的公共 api。 有人有使用計時器的解決方案 但我更喜歡在視圖出現時閃爍一次指示器。

另一個想法是使 textview 內容滾動到頂部,以便用戶可以理解有內容要滾動。 下面的代碼復制

textView.setContentOffset(.zero, animated: true)

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()
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM