//定义一个全局变量animationid来判断是哪个动画执行完成,也可以有[self.headimageview.layer.animationforkey isequeueto"haha"]
1。监听动画完成要把代理赋给当前类
-(void)viewdidload{
[super viewdidload];
[self imaganimation]
}
-(void)imaganimation{
CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
positionAnimation.delegate= self;
positionAnimation.beginTime = 0.f; //按照圆弧移动动画
positionAnimation.fromValue = [NSNumber numberWithDouble:0.f];
positionAnimation.toValue = [NSNumber numberWithDouble:125];
positionAnimation.duration = 1.0f;
positionAnimation.repeatCount = 1;
positionAnimation.removedOnCompletion = NO;
positionAnimation.fillMode = @"forwards";
[_headimageview.layer addAnimation:positionAnimation forKey:@"CQPosition"];
}
pragma mark -CAAnimationDelegate
- (void)animationDidStart:(CAAnimation *)anim
{
NSLog(@"animationDidStart%@",_headimageview.layer.animationKeys);
}
-
(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"animationDidStop%@",_headimageview.layer.animationKeys);
if (_animatedid==1) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必须写opacity才行。
animation.fromValue = [NSNumber numberWithFloat:1.0f];
animation.delegate = self;
animation.toValue = [NSNumber numberWithFloat:0.0f];//这是透明度。
animation.autoreverses = YES;
animation.duration = 1.0f;
animation.repeatCount = 2;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///没有的话是均匀的动画
animation.fillMode = @"forwards";
[self.headimageview.layer addAnimation:animation forKey:@"pmopacity"];
}else{YC_ScreenDeviceVC *devicevc =[[YC_ScreenDeviceVC alloc]init]; YCBaseNavVC *navvc = [[YCBaseNavVC alloc]initWithRootViewController:devicevc]; [[UIApplication sharedApplication].delegate window].rootViewController = navvc; [[[UIApplication sharedApplication].delegate window] makeKeyAndVisible];
}
_animatedid++;
}
网友评论