0

由于 UIView 动画是由 CAAnimation 支持的,所以我猜,当 id do 时,会触发UIView animateWithDuration:animationsCALayer 。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
4

2 回答 2

1

假设它被视为图层上的隐式动画,在这种情况下,您将改为 swizzle actionForKey:

于 2013-08-16T10:14:20.370 回答
0

你设置delegate动画了吗?

animation.delegate = self
于 2013-08-16T09:43:36.537 回答