Frage

Since UIView Animation is backed by CAAnimation, so I guess, when id do UIView animateWithDuration:animations, CALayer's addAnimation:forKey: will be triggered. so i did a method swizzling and output some info in it.

#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

nothing happened. but if i show an UIAlertView, it is triggered.

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

[alertView show];

this is the result:

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
War es hilfreich?

Lösung

I'm assuming that it's being treated as an implicit animation on the layer in which case you would swizzle actionForKey: instead.

Andere Tipps

have u set the delegate of animation?

animation.delegate = self
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top