UITextView starts at Bottom or Middle of the text

后端 未结 19 1596
谎友^
谎友^ 2020-12-04 13:09

I\'ll get right to it. I have a UItextView placed in my view that when needs to scroll to see all the text (when a lot of text is present in the textView) the t

19条回答
  •  再見小時候
    2020-12-04 13:38

    For Swift >2.2, I had issues with iOS 8 and iOS 9 using above methods as there are no single answer that works so here is what I did to make it work for both.

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    
        if #available(iOS 9.0, *) {
            textView.scrollEnabled = false
        }
    
        self.textView.scrollRangeToVisible(NSMakeRange(0, 0))
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    
        if #available(iOS 9.0, *) {
            textView.scrollEnabled = true
        }
    }
    

提交回复
热议问题