菜鸟教程小白 发表于 2022-12-11 18:24:53

ios - UITextView Scroll View 直接显示第二行


                                            <p><p>我有一个 <code>UITextView</code> 有 290 高度修复。因此,每当文本超过高度时,就会启用滚动,但在我的情况下,我不明白为什么滚动显示第二行文本。 <a href="/image/XNVq3.png" rel="noreferrer noopener nofollow"><img src="/image/XNVq3.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>请尝试以下代码</p>

<p><strong> objective-c :</strong></p>

<pre><code>;
</code></pre>

<p><strong> swift :</strong></p>

<pre><code>self.textView.scrollRangeToVisible(NSMakeRange(0, 0))
</code></pre>

<p><strong>Swift 2(替代解决方案)</strong></p>

<p>将此覆盖的方法添加到您的 ViewController</p>

<pre><code>override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    textView.setContentOffset(CGPointZero, animated: false)
}
</code></pre>

<p><strong>Swift 3(语法编辑)</strong></p>

<pre><code>override func viewDidLayoutSubviews() {
      super.viewDidLayoutSubviews()
      textView.setContentOffset(CGPoint.zero, animated: false)
    }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UITextView Scroll View 直接显示第二行,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45433499/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45433499/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UITextView Scroll View 直接显示第二行