#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