UIScrollView Incorrectly Scrolls When Selecting Text in UITextView on iOS 15

I'm experiencing an issue in my iOS app where tapping to select text in a UITextView that is embedded within a UIScrollView causes the scroll view to jump to an incorrect position. This problem seems to occur only on iOS 15. Does anyone know how to fix this issue, or is there a known bug regarding this behavior on iOS 15?

class ViewController: UIViewController, UITextViewDelegate, UIGestureRecognizerDelegate {

    @IBOutlet weak var textView: UITextView!
    @IBOutlet weak var scrollView: UIScrollView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        textView.isScrollEnabled = false


        textView.layoutManager.allowsNonContiguousLayout = false
    }
}

Answered by Claude31 in 799151022

Why do you disable the scroll of the textView ?

textView.isScrollEnabled = false

But it is not a very good idea to embed a TextView (scrollView) inside a ScrollView: touch events may mix up, as explained here: https://stackoverflow.com/questions/27652334/uitextview-inside-uiscrollview-with-autolayout

Accepted Answer

Why do you disable the scroll of the textView ?

textView.isScrollEnabled = false

But it is not a very good idea to embed a TextView (scrollView) inside a ScrollView: touch events may mix up, as explained here: https://stackoverflow.com/questions/27652334/uitextview-inside-uiscrollview-with-autolayout

@Claude31 is spot on here. To add to that, UITextView is a UIScrollView so you might not want to embed that within another UIScrollView. Just set the constraints between the UITextView and the contentView(self.view)

UIScrollView Incorrectly Scrolls When Selecting Text in UITextView on iOS 15
 
 
Q