iOS(学习) 一个简单的动画效果

参考QQ(语音)按住说话。类似的效果

#import "ViewController.h"

@interface ViewController ()
{
    UIImageView *imageView;
    UILabel *label;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];


    label = [[UILabel alloc] init];
    label.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2-40, [UIScreen mainScreen].bounds.size.height/2, 80, 40);
    label.text = @"按住说话";
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];


    imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2-20, [UIScreen mainScreen].bounds.size.height/2, 40, 40);

    //动画属性  @property (nullable, nonatomic, copy) NSArray<UIImage *> *animationImages
    imageView.animationImages = @[[UIImage imageNamed:@"11"], [UIImage imageNamed:@"22"], [UIImage imageNamed:@"33"]];

    //图片轮播时间
    imageView.animationDuration = 1;

    //imageView.hidden = YES;


    [self.view addSubview:imageView];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2-30, [UIScreen mainScreen].bounds.size.height/2+100, 60, 60);

    //用图片当按钮
    [button setImage:[UIImage imageNamed:@"QQMIC"] forState:UIControlStateNormal];

    // UIControlEventTouchDown 按下(一直按着)
    [button addTarget:self action:@selector(buttonStartAction:) forControlEvents:UIControlEventTouchDown];
    // UIControlEventTouchUpInside  松手
    [button addTarget:self action:@selector(buttonEndAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}

//按下 执行方法
- (void)buttonStartAction:(UIButton *)sender {
    NSLog(@"开始");
    //开始执行动画
    [imageView startAnimating];
    //按下 显示
    imageView.hidden = NO;

    //按下时 label 隐藏
    label.hidden = YES;
}

//松手执行方法
- (void)buttonEndAction:(UIButton *)sender {
    NSLog(@"结束");
    //停止动画
    [imageView stopAnimating];

    //松手 隐藏
    imageView.hidden = YES;

    //松手 label 显示
    label.hidden = NO;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

这里写图片描述

更多的源码下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值