停駐模式+GIF,停駐模式gif

來源:互聯網
上載者:User

停駐模式+GIF,停駐模式gif

UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(0,20,200,200)];

redView.backgroundColor=[UIColor redColor];

//允許子視圖放大或縮小 預設autoresizeSubviews的就為YES

redView.autoresizeSubview=YES;

redView.tag=100;

[self.window addSubview:redView];

 

UIView *yellowView=[[UIView alloc]initWithFrame:CGRectMake(0,0,100,100)];

//按照可縮放的高度進行放大或縮小

yellowView.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexbleWidth;

yellowView.backgroundColor=[UIColor yellowColor];

[redView addSubview:yellowView];

UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem];

[btn setTitle:@"放大" forState:UIControlStateNormal];

btn.frame=CGRectMake(100,300,100,30);

[self.window addSubview:btn];

[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

 

 

-(void)btnClick:(UIButton *)bt

{
UIView *redView=[self.window viewWithTag:100];

redView.frame=CGRectMake(redView.frame.origin.x,redView.frame.origin.y,redView.frame.size.width+10,redView.frame.size.height+10);

}

//GIF 用第三方庫

(1)

//獲得圖片路徑

NSString *imgPath=[[NSBundle mainBundle]pathForResource:@"FlagZombie" ofType:@"gif"];

//通過指定路徑下的檔案初始化NSData

NSData *data=[[NSData alloc]initWithContentOfFile:imgPath];

UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100,100,50,50)];

imgView.image=[UIImage animatedImageWithAnimatedGIFData:data];

[self.window addSubview:imgView];

(2)

NSURL *url=[[NSBundle mainBundle]URLForResource:@"FlagZombie" withExtension:@"gif"];

UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(200,100,80,80)];

//通過類別中的方法animatedImageWithAnimatedGIFURL實現Gif的圖片的播放

imgView.imge=[UIImage animatedImageWithAnimatedGIFURL:url];

imgView.tag=100;

[self.window addSubview:imgView];

//通過定時器實現每一段時間調用move方法

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(move) userInfo:nil repeats:YES];

-(void)move{
UIImageView *imgView=(UIImageView *)[self.window viewWithTag:100];

//當圖片的x座標大於80,沒調用move都使圖片向左側位移5個單位

if(imgView.frame.origin.x>80){
imgView.frame=CGRectMake(imgView.frame.origin.x-5,imgView.frame.origin.y,imgView.frame.size.width,imgView.frame.size.height);

     }

}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.