Dock mode + GIF, dock mode gif

Source: Internet
Author: User

Dock mode + GIF, dock mode gif

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

RedView. backgroundColor = [UIColor redColor];

// Allows the sub-view to zoom in or out. The default value of autoresizeSubviews is YES.

RedView. autoresizeSubview = YES;

RedView. tag = 100;

[Self. window addSubview: redView];

 

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

// Zoom in or out at a scalable height

YellowView. autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexbleWidth;

YellowView. backgroundColor = [UIColor yellowColor];

[RedView addSubview: yellowView];

UIButton * btn = [UIButton buttonWithType: UIButtonTypeSystem];

[Btn setTitle: @ "zoom in" 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 );

}

// Third-party GIF Library

(1)

// Obtain the image path

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

// Initialize NSData through a file in the specified path

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,)];

// Use the method in the category to play the Gif image using the animatedImageWithAnimatedGIFURL Method

ImgView. imge = [UIImage animatedImageWithAnimatedGIFURL: url];

ImgView. tag= 100;

[Self. window addSubview: imgView];

// Call the move method every time using a timer

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

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

// When the x coordinate of the image is greater than 80, move is not called to offset the image to the left by 5 units

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 );

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.