This new approach will simplify your original code, allowing you to move to a specific end location.
Note: Efficiency depends on how far the target end location is from the start of the document.
override func moveToEndOfDocument(_ sender: Any?) {
moveToEndLocation(textLayoutManager.documentRange.endLocation)
}
func moveToEndLocation(_ targetEndLocation: NSTextLocation) {
var lineFragmentFrame: CGRect = .null
textLayoutManager.enumerateTextLayoutFragments(from: textLayoutManager.documentRange.location, options: [.ensuresLayout]) { layoutFragment in
if layoutFragment.rangeInElement.endLocation.compare(targetEndLocation) != .orderedAscending {
lineFragmentFrame = layoutFragment.layoutFragmentFrame
return false
}
return true
}
textLayoutManager.textViewportLayoutController.layoutViewport()
self.scrollToVisible(lineFragmentFrame)
}
Topic:
UI Frameworks
SubTopic:
General
Tags: