#简单的UIView 动画 UIView:
在ios中,需要完成一些动画。我们能够通过对view或者对layer进行操作来完成动画。在每一个view中,都有一个layer属性。对view的操作相比较对layer的操作来说,显得相对的简单。view与layer最大的不同,在于同样的动画,我们通过对view操作来达到目的与对layer操作达到目的是不同的。对layer操作是图层的渲染结果并不会触发相应的点击事件,他没有相对应的点击事件,而view拥有点击事件,拥有事件响应链。但layer可以做出复杂酷炫的动画,而view很难。
创建一个空白的view
aniView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];aniView.center = self.view.center;aniView.backgroundColor = [UIColor redColor];[self.view addSubview:aniView];
然后我们可以对它进行放大缩小
[UIView animateWithDuration:1 animations:^{ aniView.transform = CGAffineTransformScale(aniView.transform, 1.5, 1.5); aniView.layer.cornerRadius = 100; }completion:^(BOOL finished) { aniView.transform = CGAffineTransformIdentity; aniView.layer.cornerRadius = 0;}];
animateWithDuration:1,代表完成这个动画的时间,(1.5, 1.5)1是这个view的本身大小,大于1放大,小于1缩小。cornerRadius代表的是圆角的弧度,我们可以通过它得到一个不那么棱角分明的形状。
completion动画完成后的操作,不设置的话,view会成为原来的形状。
[UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionCurveLinear animations:^{ aniView.layer.cornerRadius = 50; aniView.transform = CGAffineTransformScale(aniView.transform, 2, 2); } completion:^(BOOL finished) { aniView.transform = CGAffineTransformIdentity; aniView.layer.cornerRadius = 0;}];
设置动画的延迟进行, delay:延迟的秒数, options: 动画的线性变换
UIViewAnimationOptionCurveEaseInOut 进入、出去时加速
UIViewAnimationOptionCurveEaseIn 进入时加速
UIViewAnimationOptionCurveEaseOut 出去时加速
UIViewAnimationOptionCurveLinear 匀速
带有缓冲效应的动画,Damping:缓冲值(0~1),值越小缓冲越大,Velocity: 动画播放速度
[UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:1 options:0 animations:^{ aniView.layer.cornerRadius = 50; aniView.transform = CGAffineTransformScale(aniView.transform, 2, 2);} completion:^(BOOL finished) { aniView.transform = CGAffineTransformIdentity; aniView.layer.cornerRadius = 0;}];
视图转场动画, 从一个视图到另一个视图的转化过程,options:转场样式
[UIView transitionFromView:self.view toView:aniView duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) { }];
UIViewAnimationOptionTransitionNone 默认
UIViewAnimationOptionTransitionFlipFromLeft 从左边转换
UIViewAnimationOptionTransitionFlipFromRight 右——>左
UIViewAnimationOptionTransitionCurlUp 向上卷
UIViewAnimationOptionTransitionCurlDown 向下
UIViewAnimationOptionTransitionCrossDissolve 溶解
UIViewAnimationOptionTransitionFlipFromTop 上——>下
UIViewAnimationOptionTransitionFlipFromBottom 下——>上
**嵌套动画:**多个动画组合成一个动画组
[UIView animateWithDuration:2 animations:^{ aniView.transform = CGAffineTransformScale(aniView.transform, 2, 2); } completion:^(BOOL finished) { [UIView animateWithDuration:2 animations:^{ aniView.layer.cornerRadius = 50; } completion:^(BOOL finished) { [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1 options:0 animations:^{ aniView.transform = CGAffineTransformScale(aniView.transform, 0.5, 0.5); } completion:^(BOOL finished) { }]; }]; }];
简单的view的动画操作就完成,还有许多不好的错误的地方,请指正