YHVelocityProxy.m
1.55 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
58
//
// YHVelocityProxy.m
// YHAnimationDemo
//
// Created by gaoqiang xu on 2/11/15.
// Copyright (c) 2015 gaoqiang. All rights reserved.
//
#import "YHVelocityProxy.h"
#import "YHVelocityProxyInternal.h"
#import <objc/runtime.h>
static char kVelocityProxyKey;
@implementation YHVelocityProxy
+ (NSString *)propertyNameForSelector:(SEL)selector {
NSString *selectorName = NSStringFromSelector(selector);
if (![selectorName hasPrefix:@"set"]) {
[NSException raise:NSInternalInconsistencyException format:@"Spring animation only takes setters."];
}
NSString *propertyName = [selectorName substringWithRange:NSMakeRange(3, [selectorName length]-4)];
propertyName = [[[propertyName substringWithRange:NSMakeRange(0, 1)] lowercaseString] stringByAppendingString:[propertyName substringFromIndex:1]];
return propertyName;
}
- (void)completeInvocationWithPropertyName:(NSString *)propertyName andValue:(id)value {
self.velocity = value;
}
@end
@implementation NSObject (YHVelocityProxyInternal)
- (YHVelocityProxy *)yh_velocityProxy {
YHVelocityProxy *proxy = objc_getAssociatedObject(self, &kVelocityProxyKey);
if (!proxy) {
proxy = [[YHVelocityProxy alloc] initWithObject:self];
objc_setAssociatedObject(self, &kVelocityProxyKey, proxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return proxy;
}
@end
@implementation NSObject (YHVelocityProxy)
- (id)pop_velocity {
return (id)[self yh_velocityProxy];
}
- (void)setPop_velocity:(id)velocity {
[self yh_velocityProxy].velocity = velocity;
}
@end