YHStopProxy.m
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// YHStopProxy.m
// YHAnimationDemo
//
// Created by gaoqiang xu on 2/11/15.
// Copyright (c) 2015 gaoqiang. All rights reserved.
//
#import "YHStopProxy.h"
#import "POP.h"
#import <objc/runtime.h>
static char kStopAnimationProxyKey;
@implementation YHStopProxy
+ (NSString *)propertyNameForSelector:(SEL)selector {
return [self propertyNameFromGetterSelector:selector];
}
/**
* 停止对应的动画
对该对象发送消息,只要对应到动画属性,就会取出对应的动画并停止掉
*
* @param propertyName 动画属性
* @param value 值
*/
- (void)completeInvocationWithPropertyName:(NSString *)propertyName andValue:(id)value {
if ([propertyName hasPrefix:@"pop_"]) {
propertyName = [propertyName substringFromIndex:4];
}
// remove animation
POPPropertyAnimation *animation = [self.object pop_animationForKey:propertyName];
if (animation) {
[self.object pop_removeAnimationForKey:propertyName];
}
}
@end
@implementation NSObject (YHStopProxy)
- (YHStopProxy *)yh_stopAnimationProxy {
YHStopProxy *proxy = objc_getAssociatedObject(self, &kStopAnimationProxyKey);
if (!proxy) {
proxy = [[YHStopProxy alloc] initWithObject:self];
objc_setAssociatedObject(self, &kStopAnimationProxyKey, proxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return proxy;
}
- (instancetype)pop_stop {
return (id)[self yh_stopAnimationProxy];
}
@end