iOS核心动画内存泄漏CAKeyframeAnimation

iOS核心动画内存泄漏CAKeyframeAnimation_第1张图片
image.png
#import 
@protocol YLBAnimationWeakDelegate 
@optional
- (void)animationDidStart:(CAAnimation *)anim;
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@end

@interface YLBAnimationDelegateManager : NSObject 
@property (weak, nonatomic) id delegate;
@end

@implementation YLBAnimationDelegateManager
- (void)animationDidStart:(CAAnimation *)anim {
    if (_delegate && [_delegate respondsToSelector:@selector(animationDidStart:)]) {
        [_delegate animationDidStart:anim];
    }
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    if (_delegate && [_delegate respondsToSelector:@selector(animationDidStop:finished:)]) {
        [_delegate animationDidStop:anim finished:flag];
    }
}
@end

使用方法:

CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
YLBAnimationDelegateManager * manager = [YLBAnimationDelegateManager new]; //创建实例
manager.delegate = self; //进行弱引用
moveAnimation.delegate = manager; //进行强引用

你可能感兴趣的:(iOS核心动画内存泄漏CAKeyframeAnimation)