Skip to content

Commit

Permalink
Renamed method for registering custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcheok committed May 10, 2014
1 parent 7b7462a commit 107ac7a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions POP+MCAnimate/Animations/MCAnimationProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@

@interface NSObject (MCAnimationProxy)

+ (void)pop_addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold;
+ (void)pop_addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold __attribute__((deprecated));
+ (void)pop_registerAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold;

@end

#ifdef MCANIMATE_SHORTHAND

@interface NSObject (MCAnimationProxy_DropPrefix)

+ (void)addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold;
+ (void)addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold __attribute__((deprecated));
+ (void)registerAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold;

@end

@implementation NSObject (MCAnimationProxy_DropPrefix)

+ (void)addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold {
[self pop_addAnimatablePropertyWithName:propertyName readBlock:readBlock writeBlock:writeBlock threshold:threshold];
[self pop_registerAnimatablePropertyWithName:propertyName readBlock:readBlock writeBlock:writeBlock threshold:threshold];
}

+ (void)registerAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id obj, CGFloat values[]))readBlock writeBlock:(void (^)(id obj, const CGFloat values[]))writeBlock threshold:(CGFloat)threshold {
[self pop_registerAnimatablePropertyWithName:propertyName readBlock:readBlock writeBlock:writeBlock threshold:threshold];
}

@end
Expand Down
4 changes: 4 additions & 0 deletions POP+MCAnimate/Animations/MCAnimationProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ - (POPAnimatableProperty *)__animatablePropertyForPropertyName:(NSString *)prope
@implementation NSObject (MCAnimationProxy)

+ (void)pop_addAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id, CGFloat *))readBlock writeBlock:(void (^)(id, const CGFloat *))writeBlock threshold:(CGFloat)threshold {
[self pop_registerAnimatablePropertyWithName:propertyName readBlock:readBlock writeBlock:writeBlock threshold:threshold];
}

+ (void)pop_registerAnimatablePropertyWithName:(NSString *)propertyName readBlock:(void (^)(id, CGFloat *))readBlock writeBlock:(void (^)(id, const CGFloat *))writeBlock threshold:(CGFloat)threshold {
NSString *className = NSStringFromClass(self);
NSString *domainName = [NSString stringWithFormat:@"%@.%@", className, propertyName];
POPAnimatableProperty *property = [POPAnimatableProperty propertyWithName:domainName initializer: ^(POPMutableAnimatableProperty *prop) {
Expand Down
2 changes: 1 addition & 1 deletion POP-Demo/POP-Demo/MCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ - (void)viewDidLoad {
#endif

// declare custom property
[UILabel addAnimatablePropertyWithName:@"textColor" readBlock:^(UILabel *label, CGFloat values[]) {
[UILabel registerAnimatablePropertyWithName:@"textColor" readBlock:^(UILabel *label, CGFloat values[]) {
POPUIColorGetRGBAComponents(label.textColor, values);
} writeBlock:^(UILabel *label, const CGFloat values[]) {
label.textColor = POPUIColorRGBACreate(values);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The `finished` flag in the completion handler will return `NO` if any of the ani

You can make any property animatable by first declaring it:

[UILabel addAnimatablePropertyWithName:@"textColor" readBlock:^(UILabel *label, CGFloat values[]) {
[UILabel registerAnimatablePropertyWithName:@"textColor" readBlock:^(UILabel *label, CGFloat values[]) {
POPUIColorGetRGBAComponents(label.textColor, values);
} writeBlock:^(UILabel *label, const CGFloat values[]) {
label.textColor = POPUIColorRGBACreate(values);
Expand Down

0 comments on commit 107ac7a

Please sign in to comment.