
正文
UI变化之动画效果
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
很多时候我们在需要动态的改变某一个场景下的显示。
最常见的一个场景就是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
}];







