菜鸟教程小白 发表于 2022-12-13 07:22:36

ios - CATransform3D 让我的 UITextView 消失?


                                            <p><p>所以我有一个 UITextView,它应该在视觉上位于屏幕的底部边缘,然后向上拉伸(stretch)并返回“进入”屏幕,“星球大战”打开爬行样式。</p>

<p>经过多次谷歌搜索等,我觉得我的代码看起来像是适合这项工作的......但不是设置我正在寻找的透视图,这只是让 UITextView 完全消失!</p >

<p> TextView 设置在带有 Spring /支柱(无自动布局)的 Storyboard 中,使其固定在主视图的顶部和底部,距离每侧约 20 像素,并且 Spring 在两个方向上都处于事件状态。它的导出连接到 self.infoTextView。如果我不对它应用任何转换,它会按照我的预期显示。</p>

<p>但是当我在 viewDidLoad 中触发下面的代码时, TextView 就完全消失了。我确定我遗漏了一些东西,但我似乎无法弄清楚 t 是什么。</p>

<pre><code>CGRect frame = self.infoTextView.layer.frame;
self.infoTextView.layer.anchorPoint = CGPointMake(.5f, 1.0f);
self.infoTextView.layer.frame = frame;

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 1.57, 0, 1, 0);
self.infoTextView.layer.transform = rotationAndPerspectiveTransform;
</code></pre>

<p>谢谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您需要在代码中修改两件事:</p>

<ol>
<li>旋转轴。您正在围绕 Y 轴旋转它。要获得
效果你需要将旋转变换更改为
绕 X 轴转动。</li>
<li>要获得“星球大战开场爬行式”效果,您需要设置负角度或负视角。</li>
</ol>

<p>此外,您可能希望设置更“强烈”的视角以实现更戏剧化的效果。</p>

<p>这是一个基于您的转换代码的示例:</p>

<pre><code>CGFloat angle = -45;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / 200;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, angle / 180.0 * M_PI, 1, 0, 0);
self.infoTextView.layer.transform = rotationAndPerspectiveTransform;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - CATransform3D 让我的 UITextView 消失?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/30408609/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/30408609/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - CATransform3D 让我的 UITextView 消失?