Skip to content

Instantly share code, notes, and snippets.

@kocyigityunus
Created April 14, 2015 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kocyigityunus/0af6dbe65344a33e7c73 to your computer and use it in GitHub Desktop.
Save kocyigityunus/0af6dbe65344a33e7c73 to your computer and use it in GitHub Desktop.
async display kit -- AsControlNode states
#import "PRImageNode.h"
#import <AsyncDisplayKit/ASControlNode+Subclasses.h>
@interface PRImageNode(){
// PRImageNode class is derived from ASImageNode which derived from ASControlNode
BOOL _touched;
}
@end
@implementation PRImageNode
-(id)init{
if( !( self = [super init] ) )
return nil;
return self;
}
-(void) makeTouched{
self.borderWidth = 5;
self.borderColor = [UIColor blackColor].CGColor;
self.cornerRadius = 3;
}
-(void) cancelTouched{
self.borderWidth = 0;
self.cornerRadius = 0;
}
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent{
_touched = true;
[self makeTouched];
return YES;
}
-(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent{
CGPoint touchLocation = [touch locationInView:self.view];
if( CGRectContainsPoint(self.bounds, touchLocation) ){
if( !_touched ){
_touched = true;
[self makeTouched];
}
}else{
[self cancelTrackingWithEvent:touchEvent];
_touched = false;
[self cancelTouched];
}
return YES;
}
-(void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent{
_touched = false;
[self cancelTouched];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment