GIF动图 SegmentControl

准备工作不赘述

放入三组连续的图片
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];
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值