Heim > Fragen und Antworten > Hauptteil
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue = @(1.0);
animation.toValue = @(1.5);
animation.duration = 0.3f;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.delegate = self;
[_view1.layer addAnimation:animation forKey:@"animationPosition1"];
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"dfdfdfdf:%@",[_view1.layer valueForKey:@"animationPosition1"]); // 为什么这句是null
if ([_view1.layer valueForKey:@"animationPosition1"] == anim) {
NSLog(@"anim:%@",anim);
}
}
我就想达到某一个动画结束做某件事 但是 NSLog(@"dfdfdfdf:%@",[_view1.layer valueForKey:@"animationPosition1"]);始终为空 求解答
阿神2017-04-17 17:58:56
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue = @(1.0);
animation.toValue = @(1.5);
animation.duration = 0.3f;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.delegate = self;
[animation setValue:@"fi" forKey:@"presentKey"];
[_view1.layer addAnimation:animation forKey:@"animationPosition1"];
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if ([anim valueForKey:@"presentKey"]) {
//todo
}
}
阿神2017-04-17 17:58:56
或者用字符串判断 [[_view1.layer animationKeys].firstObject isEqualToString:@"animationPosition1"];