UITextView不能滚动

2020-03-23  本文已影响0人  蛋哥是只猫

使用UITextView时,进入页面时不能够滚动,但是输入文字换行后可以滚动,解决方法

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        let str = self.textView.text
        let h = str.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context:nil).size.height
        self.textView.contentSize = CGSize(width: 0, height: h!+5)
        return super.hitTest(point, with: event)
    }
上一篇下一篇

猜你喜欢

热点阅读