Created
September 29, 2012 16:49
-
-
Save C4Code/3804565 to your computer and use it in GitHub Desktop.
PAN Gesture for a Line
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
// | |
// C4WorkSpace.m | |
// linePAN | |
// | |
// Created by moi on 12-09-29. | |
// Copyright (c) 2012 moi. All rights reserved. | |
// | |
/* | |
One of the main problems in trying to drag a LINE is that, by default, you cannot add gestures to lines. | |
The reason is that there is "nothing" to hit-test... This is an issue that arises from the CAShapeLayer, or more specifically the UIBezier path. Bezier paths that are straight lines cannot be hit-test because they "sort of" have NO area to hit... | |
To move a line with a gesture, you can ADD the line to an invisible shape. | |
This example will show you how to do this. | |
*/ | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *line; | |
} | |
-(void)setup { | |
//create the line | |
CGPoint p[2] = {CGPointMake(0, 0),CGPointMake(100, 100)}; | |
line = [C4Shape line:p]; | |
//create a shape the size of the line's frame | |
C4Shape *backgroundShape = [C4Shape rect:line.frame]; | |
backgroundShape.fillColor = [UIColor clearColor]; | |
backgroundShape.lineWidth = 0.0f; | |
//add the line to the shape | |
[backgroundShape addShape:line]; | |
//add the gesture recognizer to the SHAPE | |
[backgroundShape addGesture:PAN name:@"pan" action:@"move:"]; | |
[self.canvas addShape:backgroundShape]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment