动画显示视图 [英] Animating the display of a View

查看:76
本文介绍了动画显示视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图上添加了一个按钮(视图与按钮的大小相同)。单击该按钮时,必须显示新视图。因此,在按钮的事件处理程序中,我添加了newview作为添加按钮的视图的子视图,以便在单击按钮时显示newview。我需要做的是,当我点击按钮时,必须从上到下调用​​newview(它必须看起来像从按钮的视图向下滑动)。再次单击相同的按钮时,新视图必须向后滚动(滑动)并消失。我知道我需要应用一些动画来获得这种效果。但我不知道该怎么做。能否帮我提一些想法。

I have added a button on a view(the view is of the same size as the button). When that button is clicked a new view has to be displayed. So in the button's event handler I have added the newview as a subview of the view on which the button is added, so that the newview gets displayed when the button is clicked. The thing here I need to do is, when I click on the button, the newview has to be invoked from top to bottom (it has to look like it slides down from the button's view). When the same button is clicked again, the newview has to scrollback(slide) and disappear. I know that I need to apply some animation stuff to get this effect. But I have no idea how to do this. Can you please help me giving some ideas.

提前致谢!!!

推荐答案

你可以设置窗口大小的动画来模拟顶部的幻灯片,如下所示:

Well you can animate the size of your window to simulate the slide from top like this:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, viewTargetHeight);
[UIView commitAnimations];

确保在创建时将视图高度设置为0.

Make sure you set the view height to 0 when you create it.

要将其向上滚动,只需执行相反的操作

To scroll it back up just do the opposite

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, 0);
[UIView commitAnimations];

如果你真的想让你的新视图滑动,你可以试试动画大小和位置而你也可能需要用另一个视图剪辑你的动画视图。

If you actually want your new view to slide you can try animating both the size and the position and you'll also probably need to clip your animated view with another view.

这篇关于动画显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆