iOS开发之 UIView动画图,animationView
2015-09-14 16:29
381 查看
效果图就如汤姆猫,这个就不用我展示了把
<span style="font-size:14px;"> UIImageView *animationView; NSMutableArray *imageList;</span>
<span style="font-size:14px;"> self.view.backgroundColor = [UIColor whiteColor]; [self loadData]; // UIImage *image = [UIImage imageNamed:@"cymbal_00.jpg"]; animationView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)]; // 设置UIImageView播放的动态数组图 animationView.animationImages = imageList; // 播放一组动画需要的时间 animationView.animationDuration = 10; //// -1 循环播放 animationView.animationRepeatCount = -1; // [self.view addSubview:animationView]; // [animationView startAnimating];//让动画开始 // [animationView stopAnimating];//让动画结束 // animationView.isAnimating //判断动画是否播放 UIButton *b1 = [UIButton buttonWithType:UIButtonTypeCustom]; b1.backgroundColor = [UIColor whiteColor]; b1.frame = CGRectMake(0, 600, 50, 50); [b1 setTitle:@"开始" forState:UIControlStateNormal]; [b1 setTitle:@"暂停" forState:UIControlStateSelected]; [b1 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; [b1 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; b1.showsTouchWhenHighlighted = YES; [b1 addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:b1]; NSTimer *timer = [NSTimer timerWithTimeInterval:5 target:self selector:@selector(moveAnimation) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode]; } - (void)loadData { // 当调试的时候 打印数组的值 是nil或者null 意味着我们没有初始化对象 或者有被赋值为nil或者null(数组对象就会被销毁)的情况 imageList = [[NSMutableArray alloc]init]; for (int i = 0; i<=25; i++) { NSString *imageName = [NSString stringWithFormat:@"cymbal_%02d.jpg",i]; [imageList addObject:[UIImage imageNamed:imageName]]; } NSLog(@"%@",imageList); } - (void)play:(UIButton *)sender { if (sender.selected != YES) { // 播放动画 重置按钮的title sender.selected = YES; [animationView startAnimating]; [self moveAnimation]; }else{ sender.selected = NO; [animationView stopAnimating]; } } - (void)moveAnimation { [UIView animateWithDuration:5 animations:^{ animationView.frame = CGRectMake(250, 400, 50*2, 50*2); } completion:^(BOOL finished) { [UIView animateWithDuration:5 animations:^{ animationView.frame = CGRectMake(0 , 0, 375, 667); }]; }]; } </span>
相关文章推荐
- RMQ (Range Minimum/Maximum Query)算法
- hibernate的uuid主键生成器(使用注解)
- fineui框架
- Gson之GsonBuilder用法笔记
- 在 iOS7中 uiscrollview 不可以滑动问题
- //16进制颜色(html颜色值)字符串转为UIColor
- iOS 欢迎页面的设计 以及UIFort.familyNames
- struct2获取request,session,以及显示
- UITableView学习笔记
- Win10 Build 10537预览版截图曝光 更容易激活
- request.getParameter("scoreNumber")根据什么取值
- UIGestureRecognizer手势
- 高仿金山《电池医生》首页一键省电UI动画效果
- Android 线程中更新UI
- 为UIBtton的文字添加下划线
- iOS学习笔记:UITableView想要的都有
- Jquey学习
- access and faccessat 按照实际用户Id和实际组ID进行文件权限测试
- This virtual machine is configured for 64-bit guest operating systems. However, 64-bit operation is
- media-query