IOS三种动画总结

本文总结了iOS平台中的三种动画实现方式:UIImage动画,通过isAnimating判断动画状态;UIImageView动画,常见且实用;以及UIView动画,提供最简单的动画操作。详细介绍了每种动画的使用和特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IOS的三种动画:
1 UIImage 实现动画

2 UIImageView 动画
可以通过 isAnimating 判断动画是否正在运行

3 UIView动画

最简单的UIImage动画,输入名字会自动去找 0 1 2的系列图片
参考官方文档说明:
“This method loads a series of files by appending a series of numbers to the base file name provided in the name”

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage *image = [UIImage animatedImageNamed:@"ship-anim" duration:1];

    self.imageView.image = image;
}

UIimage View动画

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //UIImageView 动画
    NSMutableArray *mArray = [[NSMutableArray alloc]init];
    for (NSInteger i = 0; i < 40; i++) {
        //创建动画 每帧需要的 图片对象
        //UIImage *roleImage = [UIImage imageNamed:[NSString stringWithFormat:@"shaoNv3_%02ld",i+1]];

        //创建动画 每帧需要的 图片对象
        NSString *path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"shaoNv3_%02ld",i+1] ofType:@"png"];
        NSLog(@"文件 路径 i=%ld  %@",i , path);

        //file参数要的 文件的路径
        UIImage *roleImage = [UIImage imageWithContentsOfFile:path];

        [mArray addObject:roleImage];
    }
    //设置动画持续时间
    self.imageView2.animationDuration = 3;
    //设置动画播放次数   如果值为0的话 表示 无线循环
    self.imageView2.animationRepeatCount = 3;
    //将动画对象数组 赋值给 imageView 的 animatingImages 属性
    self.imageView2.animationImages = mArray;
    //运行动画
    [self.imageView2 startAnimating];

    //多长时间后 做什么事
    [self performSelector:@selector(removeImage) withObject:nil afterDelay:self.imageView2.animationDuration * self.imageView2.animationRepeatCount];
}

最常用的UIView动画:

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
    myView.alpha = 0;
    myView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:myView];

    [UIView animateWithDuration:3 animations:^{
//        CGRect frame = myView.frame;
//        frame.size = CGSizeMake(300, 300);
//        myView.frame = frame;

        CGRect bounds = myView.bounds;
        bounds.size = CGSizeMake(300, 300);
        myView.bounds = bounds;

        myView.alpha = 1;
    }];

//    [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]

//    [UIView animateWithDuration:持续时间 delay:等待时间 options:动画选项 animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值