您的位置:首页 > 产品设计 > UI/UE

UI变化之动画效果

2015-11-24 10:19 357 查看
很多时候我们在需要动态的改变某一个场景下的显示。

最常见的一个场景就是view的最大化。

我们直接设置view的frame可以实现最大化,但是这样的最大化是突变的没有动画效果。

苹果可以将这种突变“放慢”速度来达到动画的效果。

一般有两种写法,在官方文档中如下记录:

In iOS 4 and later, you create an animation block using block objects. In earlier versions of iOS, you mark the beginning and end of an animation block using special class methods of the
UIView
class.

第一种(IOS4之前做法):

[UIView beginAnimations:@"Resize" context:nil];
[UIView setAnimationDuration:1.0];
CGRect frame = self.myView.frame;
frame.size.height += 30.0;
self.myView.frame = frame;
[UIView commitAnimations];


第二种(iOS 4 and later)

可以使用块的方式:

[UIView animateWithDuration:1.0
animations:^{
CGRect frame = self.myView.frame;
frame.size.height += 30.0;
self.myView.frame = frame;
}
completion:^(BOOL finished){
// whatever you need to do when animations are complete
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: