Ios-calayer Picture Fade animation

Source: Internet
Author: User

#import"ViewController.h"

@interfaceViewcontroller ()
@property (Nonatomic,strong) Calayer *imagelayer;

@end

@implementationViewcontroller

- (void) Viewdidload {
[Super Viewdidload];
UIImage *image1 = [UIImage imagenamed:@"test1.jpg"];

//can display the image of the class, layer is the carrier of the view
//self.view.layer.contents = (__bridge ID) (image. Cgimage);

//Create a picture layer
Self.imagelayer = [Calayer layer];
Self.imageLayer.frame = Self.view.bounds;
[Self.view.layer AddSublayer:self.imageLayer];

Self.imageLayer.contents = (__bridgeID) (Image1. Cgimage);
[Self performselector: @selector (imageanimation) Withobject:nil Afterdelay:3];
}

- (void) Imageanimation {

//Implicit animations
UIImage *image2 = [UIImage imagenamed:@"test2.jpg"];
//self.imageLayer.contents = (__bridge ID) (image2. Cgimage);
Cabasicanimation *contentsanimation = [cabasicanimation animationwithkeypath:@"Contens"];
Contentsanimation.fromvalue = self.imageLayer.contents;//Original picture
Contentsanimation.tovalue = (__bridgeID) (Image2. Cgimage);//post-switch picture
Contentsanimation.duration =3. F;

Cabasicanimation *boundsanimation = [cabasicanimation animationwithkeypath:@"bounds"];
Boundsanimation.fromvalue = [Nsvalue valueWithCGRect:self.imageLayer.bounds];
Boundsanimation.tovalue = [Nsvalue valuewithcgrect:cgrectmake (Ten, -, $, $)];
Boundsanimation.duration =3. F;

Caanimationgroup *group = [Caanimationgroup animation];
Group.animations = @[contentsanimation,boundsanimation];
Group.duration =3. F;
//set the value after the end of the layer animation otherwise it will reply to the state of East Lake Money
Self.imageLayer.contents = (__bridgeID) (Image2. Cgimage);
Self.imageLayer.bounds = CGRectMake (Ten, -, $, $);
[Self.imagelayer Addanimation:group Forkey:nil];

}

Ios-calayer Picture Fade animation

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.