gpt4 book ai didi

ios - 为什么UIView动画没有触发CALayer的addAnimation :forKey:?

转载 作者:行者123 更新时间:2023-11-29 03:42:07 25 4
gpt4 key购买 nike

由于UIView动画是由CAAnimation支持的,所以我猜,当id执行UIView animateWithDuration:animations时,CALayer的addAnimation:forKey:将被触发。所以我做了一个方法调整并在其中输出一些信息。

#import "CALayer+Swizzling.h"
#import <objc/runtime.h>

@implementation CALayer (Swizzling)

+ (void)load
{
method_exchangeImplementations(class_getInstanceMethod([CALayer class], @selector(addAnimation:forKey:)), class_getInstanceMethod([CALayer class], @selector(hackedAddAnimation:forKey:)));
}

- (void)hackedAddAnimation:(CAAnimation *)animation forKey:(NSString *)key
{
[self hackedAddAnimation:animation forKey:key];
if ([animation isKindOfClass:[CABasicAnimation class]]) {
CABasicAnimation *basicAnimation = (CABasicAnimation *)animation;
if ([basicAnimation.keyPath isEqualToString:@"transform"]) {
CATransform3D transform = [basicAnimation.fromValue CATransform3DValue];
if (basicAnimation.fromValue) {
NSLog(@"fromValue:%@", NSStringFromCGAffineTransform(CATransform3DGetAffineTransform(transform)));
}
if (basicAnimation.toValue) {
NSLog(@"toValue:%@", NSStringFromCGAffineTransform(CATransform3DGetAffineTransform(transform)));
}
if (basicAnimation.byValue) {
NSLog(@"byValue:%@", NSStringFromCGAffineTransform(CATransform3DGetAffineTransform(transform)));
}
NSLog(@"timingFunction:%@", basicAnimation.timingFunction);
NSLog(@"duration:%f", basicAnimation.duration);
}
}
}
@end

什么也没发生。但如果我显示 UIAlertView,它就会被触发。

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"", nil];

[alertView show];

这是结果:

2013-08-16 17:28:39.693 Test[81840:c07] fromValue:[0.01, 0, 0, 0.01, 0, 0]
2013-08-16 17:28:39.694 Test[81840:c07] timingFunction:easeInEaseOut
2013-08-16 17:28:39.695 Test[81840:c07] duration:0.200000
2013-08-16 17:28:39.897 Test[81840:c07] fromValue:[1.1, 0, 0, 1.1, 0, 0]
2013-08-16 17:28:39.897 Test[81840:c07] timingFunction:easeInEaseOut
2013-08-16 17:28:39.899 Test[81840:c07] duration:0.100000
2013-08-16 17:28:40.000 Test[81840:c07] fromValue:[0.9, 0, 0, 0.9, 0, 0]
2013-08-16 17:28:40.000 Test[81840:c07] timingFunction:easeInEaseOut
2013-08-16 17:28:40.001 Test[81840:c07] duration:0.100000

最佳答案

假设它被视为图层上的隐式动画,在这种情况下,您可以使用 actionForKey: 来代替。

关于ios - 为什么UIView动画没有触发CALayer的addAnimation :forKey:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18270251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com