制作动画以展开和缩小UIView [英] Making an animation to expand and shrink an UIView
本文介绍了制作动画以展开和缩小UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个动画,将通过一个因素调整UIView及其内容的大小。基本上,我想制作一个动画,首先展开视图,然后收缩回原来的大小。
I want to create an animation that will resize an UIView and its contents by a factor. Basically, I want to make an animation that first expands the view then shrinks it back to the original size.
这是最好的方法是什么?我试过CALayer.contentScale,但它根本没有做任何事情。
What is the best way to do this? I tried CALayer.contentScale but it didn't do anything at all.
推荐答案
Objective-C:
Objective-C:
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformMakeScale(1.5, 1.5);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:1
animations:^{
yourView.transform = CGAffineTransformIdentity;
}];
}];
Swift:
UIView.animateWithDuration(1, animations: { () -> Void in
yourView.transform = CGAffineTransformMakeScale(1.5, 1.5)
}) { (finished: Bool) -> Void in
UIView.animateWithDuration(1, animations: { () -> Void in
yourView.transform = CGAffineTransformIdentity
})}
并用您自己的缩放值和持续时间替换缩放值和持续时间。
and replacing the scale values and durations with your own.
这篇关于制作动画以展开和缩小UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文