菜鸟教程小白 发表于 2022-12-11 21:48:15

ios - 对在 iOS 中绘制原点感到困惑


                                            <p><p><strong>代码</strong></p>

<pre><code>self.view.frame.origin.y = self.view.frame.origin.y - keyboardSize.height
</code></pre>

<p>在这里我试图将我的 View 原点设置为我的键盘 View 高度</p>

<p><strong>我的输出</strong> </p>

<p> <a href="/image/315hb.png" rel="noreferrer noopener nofollow"><img src="/image/315hb.png" alt="enter image description here"/></a> </p>

<p><strong>我的疑惑</strong></p>

<p>根据数学,我的 View 必须低于键盘,发生了什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><code>UIView</code>所在的坐标空间和你在数学课上学的笛卡尔坐标平面并不完全一样,大概是这样的:</p>

<p> <a href="/image/I8mpP.png" rel="noreferrer noopener nofollow"><img src="/image/I8mpP.png" alt="enter image description here"/></a> </p>

<p>在 UIKit 中,正 y 方向向下,负 y 方向向上。这意味着具有小 y 坐标的 View 将位于其父 View 的顶部。当你增加它的 y 坐标时,它会向下移动。它看起来像这样:</p>

<p> <a href="/image/nJbm8.png" rel="noreferrer noopener nofollow"><img src="/image/nJbm8.png" alt="enter image description here"/></a> </p>

<p>这行代码:</p>

<pre><code>self.view.frame.origin.y=self.view.frame.origin.y-keyboardSize.height
</code></pre>

<p>减小 <code>self.view</code> 的 y 坐标,从而将其 <em>向上移动</em>。多少?嗯,键盘的高度。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 对在 iOS 中绘制原点感到困惑,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/54276350/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/54276350/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 对在 iOS 中绘制原点感到困惑