菜鸟教程小白 发表于 2022-12-13 09:29:40

iphone - 从 nib 文件加载 View 时为 View 设置动画


                                            <p><p>我有一个加载包含 View 的 nib 文件的方法:</p>

<pre><code>[ loadNibNamed:@&#34;NewView&#34; owner:self options:nil];
</code></pre>

<p>我想知道是否可以在 View 加载时添加一个简单的过渡。我已经在互联网上搜索过,但我找不到任何东西。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>有很多方法可以呈现 View 并为其设置动画。</p>

<p>您可以使用 loadNibnamed 创建创建:</p>

<p> <a href="https://stackoverflow.com/questions/863321/iphone-how-to-load-a-view-using-a-nib-file-created-with-interface-builder" rel="noreferrer noopener nofollow">How to load a UIView using a nib file created with Interface Builder</a> </p>

<p>动画 View 的一种方法是以模态方式呈现它。这将从底部开始动画:</p>

<pre><code>[ presentModalViewController:navController animated:YES];
</code></pre>

<p>这些帖子展示了如何在使用 modalTransitionStyle 时更好地控制动画</p>

<p> <a href="https://stackoverflow.com/questions/237310/how-can-i-change-the-animation-style-of-a-modal-uiviewcontroller" rel="noreferrer noopener nofollow">How can I change the animation style of a modal UIViewController?</a> </p>

<p> <a href="https://stackoverflow.com/questions/6876292/iphone-presentmodalviewcontroller-with-transition-from-right" rel="noreferrer noopener nofollow">iPhone - presentModalViewController with transition from right</a> </p>

<p>另一种选择是创建一个 View ,将其作为 subview 添加到当前 View 并为框架设置动画。如果您只是加载 View ,请考虑使用 UINib - 它是在 iOS 4.0 和缓存中添加的。它的双重性能。</p>

<pre><code>UINib *nib = ;
UIView *myView = [ objectAtIndex:0]];
</code></pre>

<p>然后,您可以将其添加为 subview 。 </p>

<p>如果您想在 View 中为 subview 设置动画,请参阅本教程:</p>

<p> <a href="http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial" rel="noreferrer noopener nofollow">http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial</a> </p>

<p>具体来说:</p>

<pre><code>CGRect basketTopFrame = basketTop.frame;
basketTopFrame.origin.y = -basketTopFrame.size.height;

CGRect basketBottomFrame = basketBottom.frame;
basketBottomFrame.origin.y = self.view.bounds.size.height;

;
;
;
;

basketTop.frame = basketTopFrame;
basketBottom.frame = basketBottomFrame;

;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 从 nib 文件加载 View 时为 View 设置动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7854158/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7854158/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 从 nib 文件加载 View 时为 View 设置动画