UITextView is not scrolled to top when loaded

后端 未结 12 1292
别跟我提以往
别跟我提以往 2020-12-03 02:39

When I have text that does not fill the UITextView, it is scrolled to the top working as intended. When there is more text than will fit on screen, the UITextView is scrolle

12条回答
  •  猫巷女王i
    2020-12-03 03:13

    add the following function to your view controller class...

    Swift 3

    override func viewDidLayoutSubviews() {
        self.mainTextView.setContentOffset(.zero, animated: false)
    }
    

    Swift 2.1

    override func viewDidLayoutSubviews() {
        self.mainTextView.setContentOffset(CGPointZero, animated: false)
    }
    

    Objective C

    - (void)viewDidLayoutSubviews {
        [self.mainTextView setContentOffset:CGPointZero animated:NO];
    }
    

提交回复
热议问题