我正在开发 iPhone 应用程序,如果起点是 UILabel,我想在其中画线,我还想检测被触摸的文本。这怎么可能?请帮助我。提前谢谢,这是我画线的代码。使用这个代码我可以画线,但我想从标签画线。
- (CAShapeLayer *)createShapeLayer:(UIView *)view
{
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.lineWidth = 5.0;
[view.layer addSublayer:shapeLayer];
return shapeLayer;
}
- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
static CAShapeLayer *shapeLayer;
static CGPoint origin;
if (gesture.state == UIGestureRecognizerStateBegan)
{
shapeLayer = [self createShapeLayer:gesture.view];
origin = [gesture locationInView:gesture.view];
NSLog(@"cgpoint %f and y %f",origin.x,origin.y);
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:origin];
CGPoint location = [gesture locationInView:gesture.view];
[path1 addLineToPoint:location];
shapeLayer.path = path1.CGPath;
}
else if (gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateFailed ||
gesture.state == UIGestureRecognizerStateCancelled)
{
shapeLayer = nil;
}
}