码迷,mamicode.com
首页 > 其他好文 > 详细

不会说话的汤姆猫

时间:2015-05-16 23:20:25      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

//通过imageView播放动画
    //1.创建一个imageView
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 0, 320, 480);
    
    //2.准备要播放的图片
    NSMutableArray *films = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < 81; ++i)
    {
        //拼接文件名
        NSString *name = [[NSString alloc] initWithFormat:@"cat_knockout%04d.jpg", i];
        //文件名不存在,返回nil
        UIImage *img = [UIImage imageNamed:name];
        [films addObject:img];
    }
    //将第一张图片设置为背景
    imageView.image = films[0];
    
    //3.将胶卷交给imageView进行播放
    imageView.animationImages = films;
    //4.设置播放总时长
    imageView.animationDuration = 4.0;
    //5.是否重复播放
    imageView.animationRepeatCount = 1; //0 无限重复
    //6.开始播放
    //[imageView startAnimating];
    //结束播放
    //[imageView stopAnimating];
    
    //添加手势
    //1.创建手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    //2.添加事件处理
    [tap addTarget:self action:@selector(startImageViewAnimating:)];
    
    //3.将手势添加到指定控件上
    [imageView addGestureRecognizer:tap];
    
    //4.对于UIImageView,需要开启人机交互
    imageView.userInteractionEnabled = YES;
    
    [self.window addSubview:imageView];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)startImageViewAnimating:(UITapGestureRecognizer *)sender
{
    //获取当前点击的位置
    //[sender locationInView:]
    
    //sender.view == 被点击的视图
    UIImageView *v = (UIImageView *)sender.view;
    [v startAnimating];
}

 

不会说话的汤姆猫

标签:

原文地址:http://www.cnblogs.com/wlsky/p/4508833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!