Created
September 29, 2012 19:03
-
-
Save C4Code/3804923 to your computer and use it in GitHub Desktop.
Vertical Line Draggable
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. | |
// | |
/* | |
Here's how to make a vertical line draggable... | |
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 | |
-(void)setup { | |
//create the line | |
CGPoint p[2] = {CGPointMake(0, 0),CGPointMake(0, 100)}; | |
CGRect verticalLineRect = CGRectMake(0, 0, 44, 100); | |
C4Shape *verticalBackgroundShape = [C4Shape rect:verticalLineRect]; | |
verticalBackgroundShape.fillColor = [UIColor clearColor]; | |
verticalBackgroundShape.lineWidth = 0.0f; | |
C4Shape *verticalLine = [C4Shape line:p]; | |
[verticalBackgroundShape addShape:verticalLine]; | |
verticalLine.center = verticalBackgroundShape.center; | |
[self.canvas addShape:verticalBackgroundShape]; | |
[verticalBackgroundShape addGesture:PAN name:@"pan" action:@"move:"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment