ios UIView常用动画效果

由小变大
<pre>- (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait
{
__block BOOL done = wait;
view.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformIdentity;

} completion:^(BOOL finished) {
    done = NO;
}];
while (done == YES)
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];

}</pre>

//大变小 函数
<pre>- (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
__block BOOL done = wait;
view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformMakeScale(0, 0);
} completion:^(BOOL finished) {
done = YES;
}];
while (done == NO)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}</pre>

二,如果需要类似UIAlertView那种动画
小变大动画
<pre>- (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration
{
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = duration;
//animation.delegate = self;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
[view.layer addAnimation:animation forKey:nil];
}</pre>
原文链接
ios UIView常用动画效果
大变小
<pre>- (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
__block BOOL done = wait;
view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformMakeScale(0, 0);
view.alpha = 0.0;
} completion:^(BOOL finished) {
done = YES;
}];
while (done == NO)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}</pre>

Creating a Pop animation similar to the presentation of UIAlertView
<pre>- (void) attachPopUpAnimation{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
CATransform3D scale1 = CATransform3DMakeScale(0.5, 0.5, 1);
CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1);
CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1);
NSArray *frameValues = [NSArray arrayWithObjects: [NSValue valueWithCATransform3D:scale1], [NSValue valueWithCATransform3D:scale2], [NSValue valueWithCATransform3D:scale3], [NSValue valueWithCATransform3D:scale4], nil];
[animation setValues:frameValues];
NSArray *frameTimes = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:0.9], [NSNumber numberWithFloat:1.0], nil];
[animation setKeyTimes:frameTimes];
animation.fillMode = kCAFillModeForwards; animation.removedOnCompletion = NO;
animation.duration = .2;
[self.layer addAnimation:animation forKey:@"popup"];
}</pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,540评论 7 249
  • 他们俩相识于校园,彼此是初中同学,后来成了男女朋友。女生本科毕业后就工作了,男生是中国科技大学的在读研究生,彼此相...
    冬日艳阳阅读 146评论 0 0
  • 几天前,我坐在下班的公交车上,车子正要启动的时候,邻座来了一个女孩,只见她抱着一本英语学习辅导书,我一见这...
    阿灵Goldy阅读 427评论 -1 3
  • 面对一个陌生人,很容易敞开心扉,说很多话语、谈很多事情、诉很多衷肠,然后各奔东西,了无牵挂,谁也不认识谁。陌生人匆...
    你在微笑吗阅读 395评论 0 1
  • 想以轻松、愉快的笔法,我想我真的不易,你可以说我脆弱,也可以说我矫情,哭过,世界依旧如此~遂还是以已往笔法来书写此...
    子鱼的研究僧修行阅读 424评论 0 0