Created
July 23, 2015 02:27
-
-
Save fjolnir/8f1aab5978c082818b23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simply animates it's path along with bound change animations (if the path is changed along with the bounds that is) | |
@interface LEShapeLayer : CAShapeLayer | |
@end | |
@interface LEShapeView : UIView | |
@property(nonatomic, readonly) LEShapeLayer *shapeLayer; | |
@property(nonatomic, readonly) CGPathRef hitTestPath; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "LEShapeLayer.h" | |
@implementation LEShapeLayer | |
- (void)addAnimation:(CAAnimation *)aAnim forKey:(NSString *)aKey | |
{ | |
[super addAnimation:aAnim forKey:aKey]; | |
if([aKey isEqualToString:@"bounds"] || [aKey isEqualToString:@"bounds.size"]) { | |
CABasicAnimation * const pathAnim = [CABasicAnimation animationWithKeyPath:@"path"]; | |
pathAnim.delegate = aAnim.delegate; | |
pathAnim.duration = aAnim.duration; | |
pathAnim.fillMode = aAnim.fillMode; | |
pathAnim.timingFunction = aAnim.timingFunction; | |
[self addAnimation:pathAnim forKey:@"path"]; | |
CABasicAnimation * const contentAnim = [pathAnim copy]; | |
contentAnim.keyPath = @"contents"; | |
[self addAnimation:contentAnim forKey:@"contents"]; | |
} | |
} | |
@end | |
@implementation LEShapeView | |
+ (Class)layerClass | |
{ | |
return [LEShapeLayer class]; | |
} | |
- (LEShapeLayer *)shapeLayer | |
{ | |
return (LEShapeLayer *)self.layer; | |
} | |
- (CGPathRef)hitTestPath | |
{ | |
return self.shapeLayer.path; | |
} | |
- (BOOL)pointInside:(CGPoint const)aPoint withEvent:(UIEvent * const)aEvent | |
{ | |
return self.hitTestPath && CGPathContainsPoint(self.hitTestPath, NULL, aPoint, false); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment