IOS简单的动画

来源:互联网 发布:网络门禁系统图 编辑:程序博客网 时间:2024/05/05 08:18

前言

        在IOS客户端开发中,用到动画的地方比较少,如果是要把app做的很酷炫,那么就有必要用一些动画效果。


一、最普通的动画

1、下面这段代码是最简单的动画,只是实现了简单的位置移动和变化

- (void)viewDidLoad {    [super viewDidLoad];        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];    imgView.image = [UIImage imageNamed:@"123.jpg"];    [self.view addSubview:imgView];        [UIView beginAnimations:nil context:nil]; //设置动画开始    [UIView setAnimationDuration:3.0];//设置整个动画的时间        CGRect frame = imgView.frame;    frame.origin.x += 150;    frame.origin.y += 100;    [imgView setFrame:frame];    [UIView commitAnimations]; //动画结束    }


2、CATransition 动画

      这种动画,我觉得可以通俗的理解为视图或者控件出场的动画效果。

- (void)viewDidLoad {    [super viewDidLoad];        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];    imgView.image = [UIImage imageNamed:@"123.jpg"];    [self.view addSubview:imgView];        CATransition *animation = [CATransition animation];    animation.duration = 0.5f; //设置动画的时间    animation.timingFunction = UIViewAnimationCurveEaseInOut; //设置动画的方式    animation.fillMode = kCAFillModeBackwards;    animation.type = kCATransitionMoveIn;    animation.subtype = kCATransitionFromLeft;        [imgView.layer addAnimation:animation forKey:@"animation"];    }

3、先变大后消失的动画效果

- (void)viewDidLoad {    [super viewDidLoad];        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];    imgView.image = [UIImage imageNamed:@"123.jpg"];    [self.view addSubview:imgView];       [UIView animateWithDuration:3.25 animations:^{        CGAffineTransform newTransform = CGAffineTransformMakeScale(2.2, 2.2);        [imgView setTransform:newTransform];    }completion:^(BOOL finished){        [imgView removeFromSuperview];    }];}


4、源码下载地址:http://download.csdn.net/detail/u010545480/8615617

0 0
原创粉丝点击