单击按钮时如何通过动画显示视图? [英] How to make a view appear through animation when a button is clicked?

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

问题描述

我是编码新手。我正在创建一个应用程序,我需要在单击按钮时显示视图,并且视图应该显示为来自按钮本身。再次点击按钮,视图应该返回到按钮(动画)。

I am new to the coding. I am making an application where i need to make a view appear when a button is clicked and the view should appear as if it has come from the button itself. And on clicking the button again the view should go back to button (animated).

我有动画,如翻转,卷曲,但我不知道如何做到这一点。

I have animations like flip, curl but I don't know how to do this.

推荐答案

//这里animationButton是按钮的名称
//这里aView是一个视图

//Here animationButton is the name of the button // Here aView is a view

aView.view.center = animationButton.center;

aView.view.center=animationButton.center;

现在,将视图缩放到如图所示的小比例,这样当你制作它时,它会被显示为好像来自按钮本身。

Now,scale the view to a small scale as shown so that when you make it bib,it gets shown as if it is coming from the button itself.

CGAffineTransform trans = CGAffineTransformScale(aView.view.transform, 0.01, 0.01);

aView.view.transform = trans;   // do it instantly, no animation

[self.view addSubview:aView.view];

// now return the view to normal dimension, animating this transformation

//现在借助动画,在很大程度上通过动画缩放视图

//Now with the help of animation ,scale the view to some large extent by animation

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationCurveEaseInOut
                 animations:^{
                                  aView.view.transform =   CGAffineTransformScale(aView.view.transform, 70.0, 70.0);
                 }
                 completion:nil];

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

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