为了动画结束时的精准控制(心中一万只草泥马踏过策划),请教组里bigshot,学到了CAAnimation提供的animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;方法,可以精确知道动画结束事件。
OK,Talk is cheap,CODE SHOW~
- (void)viewDidLoad {
//创建UIImageView
UIImageView *openningAnimation = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,kUIScreen_Width,kUIScreen_Height)];
openningAnimation.image = [UIImage imageNamed:@"image_last.png"];
[self.view addSubview:openningAnimation];
//创建CAKeyframeAnimation
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.duration = animationTime;
animation.delegate = self;
//存放图片的数组
NSMutableArray *array = [NSMutableArray array];
for(NSUInteger i = 0;i < count ;i++) {
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:"image_%d.png",i]];
CGImageRef cgimg = image.CGImage;
[array addObject:(__bridge UIImage *)cgimg];
}
animation.values = array;
[openningAnimation.layer addAnimation:animation forKey:nil];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
//clearMemory
//结束事件
}
记得在动画结束时clearMemory ,因为那些高清无码大图超占内存。