GIF动图 SegmentControl
2015-08-12 20:33
656 查看
准备工作不赘述
放入三组连续的图片
MainViewController.m
放入三组连续的图片
MainViewController.m
#import "MainViewController.h" #define WIDTH self.view.frame.size.width #define HEIGHT self.view.frame.size.height @interface MainViewController () @property(nonatomic,retain)UIImageView *animation1; @property(nonatomic,retain)UIImageView *animation2; @property(nonatomic,retain)UIImageView *animation3; @property(nonatomic,retain)NSMutableArray *picArr1; @property(nonatomic,retain)NSMutableArray *picArr2; @property(nonatomic,retain)NSMutableArray *picArr3; @end @implementation MainViewController -(void)dealloc { [_animation1 release]; [_animation2 release]; [_animation3 release]; [_picArr1 release]; [_picArr2 release]; [_picArr3 release]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // self.view. self.animation1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)]; [self.view addSubview:self.animation1]; [self.animation1 release]; self.animation1.animationDuration=7; self.animation1.animationRepeatCount=7; self.picArr1=[NSMutableArray array]; for (NSInteger i=0; i<81; i++) { NSString *picName=[NSString stringWithFormat:@"drink_%02ld.jpg",i]; UIImage *image=[UIImage imageNamed:picName]; [self.picArr1 addObject:image]; } self.animation1.animationImages=self.picArr1; // [self.animation1 startAnimating]; self.animation2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)]; [self.view addSubview:self.animation2]; [self.animation2 release]; self.animation2.animationDuration=2; self.animation2.animationRepeatCount=7; self.picArr2=[NSMutableArray array]; for (NSInteger i=0; i<28; i++) { NSString *picName=[NSString stringWithFormat:@"fart_%02ld.jpg",i]; UIImage *image=[UIImage imageNamed:picName]; [self.picArr2 addObject:image]; } self.animation2.animationImages=self.picArr2; // [self.animation2 startAnimating]; self.animation3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH,HEIGHT )]; [self.view addSubview:self.animation3]; [self.animation3 release]; self.animation3.animationDuration=7; self.animation3.animationRepeatCount=7; self.picArr3=[NSMutableArray array]; for (NSInteger i=0; i<81; i++) { NSString *picName=[NSString stringWithFormat:@"knockout_%02ld.jpg",i]; UIImage *image=[UIImage imageNamed:picName]; [self.picArr3 addObject:image]; } self.animation3.animationImages=self.picArr3; // [self.animation3 startAnimating]; UISegmentedControl *seg=[[UISegmentedControl alloc]initWithItems:@[@"drink",@"fart",@"knockout"]]; seg.frame=CGRectMake(50, 600, 250, 50); seg.layer.borderWidth=1; seg.layer.cornerRadius=10; seg.layer.masksToBounds=YES; [self.view addSubview:seg]; [seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged]; [seg release]; } -(void)segAction:(UISegmentedControl *)seg { if (seg.selectedSegmentIndex==0) { [self.animation1 startAnimating]; } else if (seg.selectedSegmentIndex==1) { [self.animation2 startAnimating]; } else if (seg.selectedSegmentIndex==2) { [self.animation3 startAnimating]; } }
相关文章推荐
- GradientDrawable 的简单使用(绘制控件的背景)
- 九度OJ 题目1089:数字反转
- mac下ADB的配置和常用命令
- poj(1088)——滑雪(经典递推型动归)
- 空手套白狼--基于系统分区镜像的修改
- Linux环境PHP5.5以上连接SqlServer2008【全网最经典无错版】
- 集训第五周动态规划 G题 回文串
- Linux man命令的使用方法
- Oracle 学习之RAC(二) 环境准备
- 第 3 页:Context组件
- UIView动画事务与UIImageView动画
- 霸道的MDI
- hdu 1159/poj1458 Common Subsequence 最长公共子串
- 基于JMF RTP的网络传输媒体流
- Jvm工作原理学习笔记
- dfs 递归思想 解决排列组合的一些基础问题
- poj 1699 Best Sequence(dfs+A(n,n))
- mysql 视图
- 博客搬家
- 如期而至,OC第二天