Objective-C中的动画应用之一

一:新建一个项目工程并导入一些图片:






二:代码:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 300, 500)];
    NSMutableArray * imageArray = [[NSMutableArray alloc] init];
    
    for(int i = 0; i < 5; i++) {
        NSLog(@"the i is %d",i);
//        NSString *imageName = [NSString stringWithFormat:@"kid%d",i];
        NSString *imageName = [NSString stringWithFormat:@"play%d",i];

        NSLog(@"the name is: %@",imageName);
        
        UIImage *image = [UIImage imageNamed:imageName];
        NSLog(@"The image is %@",image);
        if(image){
        [imageArray addObject:image];
            NSLog(@"THe array is %@", imageArray);
        }
    }
    imageView.animationImages = imageArray;
    imageView.animationDuration = 1;
    imageView.animationRepeatCount = 0;
    [self.view addSubview:imageView];
    [imageView startAnimating];

    // Do any additional setup after loading the view, typically from a nib.
}

//-(IBAction)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender:(id)sender){
//    NSLog(@"this is for testing");
//}


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


@end

三:效果:






四:log:

2018-03-20 21:43:47.142213+0800 TOCAnimationa[17276:9738030] the i is 0

2018-03-20 21:43:47.142271+0800 TOCAnimationa[17276:9738030] the name is: play0

2018-03-20 21:43:47.150596+0800 TOCAnimationa[17276:9738030] The image is <UIImage: 0x1d40b67a0>, {324, 638}

2018-03-20 21:43:47.150673+0800 TOCAnimationa[17276:9738030] THe array is (

    "<UIImage: 0x1d40b67a0>, {324, 638}"

)

2018-03-20 21:43:47.150682+0800 TOCAnimationa[17276:9738030] the i is 1

2018-03-20 21:43:47.150699+0800 TOCAnimationa[17276:9738030] the name is: play1

2018-03-20 21:43:47.156305+0800 TOCAnimationa[17276:9738030] The image is <UIImage: 0x1d40b6740>, {329, 667}

2018-03-20 21:43:47.156351+0800 TOCAnimationa[17276:9738030] THe array is (

    "<UIImage: 0x1d40b67a0>, {324, 638}",

    "<UIImage: 0x1d40b6740>, {329, 667}"

)

2018-03-20 21:43:47.156361+0800 TOCAnimationa[17276:9738030] the i is 2

2018-03-20 21:43:47.156376+0800 TOCAnimationa[17276:9738030] the name is: play2

2018-03-20 21:43:47.161902+0800 TOCAnimationa[17276:9738030] The image is <UIImage: 0x1d40b6c20>, {308, 658}

2018-03-20 21:43:47.161955+0800 TOCAnimationa[17276:9738030] THe array is (

    "<UIImage: 0x1d40b67a0>, {324, 638}",

    "<UIImage: 0x1d40b6740>, {329, 667}",

    "<UIImage: 0x1d40b6c20>, {308, 658}"

)

2018-03-20 21:43:47.161965+0800 TOCAnimationa[17276:9738030] the i is 3

2018-03-20 21:43:47.161979+0800 TOCAnimationa[17276:9738030] the name is: play3

2018-03-20 21:43:47.167056+0800 TOCAnimationa[17276:9738030] The image is <UIImage: 0x1d40b6da0>, {303, 661}

2018-03-20 21:43:47.167110+0800 TOCAnimationa[17276:9738030] THe array is (

    "<UIImage: 0x1d40b67a0>, {324, 638}",

    "<UIImage: 0x1d40b6740>, {329, 667}",

    "<UIImage: 0x1d40b6c20>, {308, 658}",

    "<UIImage: 0x1d40b6da0>, {303, 661}"

)

2018-03-20 21:43:47.167119+0800 TOCAnimationa[17276:9738030] the i is 4

2018-03-20 21:43:47.167132+0800 TOCAnimationa[17276:9738030] the name is: play4

2018-03-20 21:43:47.171981+0800 TOCAnimationa[17276:9738030] The image is <UIImage: 0x1d40b6fe0>, {314, 670}

2018-03-20 21:43:47.172045+0800 TOCAnimationa[17276:9738030] THe array is (

    "<UIImage: 0x1d40b67a0>, {324, 638}",

    "<UIImage: 0x1d40b6740>, {329, 667}",

    "<UIImage: 0x1d40b6c20>, {308, 658}",

    "<UIImage: 0x1d40b6da0>, {303, 661}",

    "<UIImage: 0x1d40b6fe0>, {314, 670}"

)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值