0
我可以使用CAShapeLayer绘制线条,但我只想以45度角绘制线条。 线必须以45度角绘制,否则将从视图中移除,我如何使用CAShapeLayer绘制线,请帮助。 这里是我的绘制代码行:如何使用iPhone中的CAShapeLayer以45度角绘制线条
- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
static CGPoint origin;
CGPoint location ;
if (gesture.state == UIGestureRecognizerStateBegan)
{
shapeLayer = [self createShapeLayer:gesture.view];
origin = [gesture locationInView:gesture.view];
UIView *tappedView = [gesture.view hitTest:origin withEvent:nil];
UILabel *tempLabel = (UILabel *)tappedView;
[valuesArray addObject:tempLabel];
if(valuesArray)
{
[valuesArray removeAllObjects];
}
valuesArray = [[NSMutableArray alloc] init];
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:origin];
location = [gesture locationInView:gesture.view];
[path1 addLineToPoint:location];
shapeLayer.path = path1.CGPath;
}
}
- (CAShapeLayer *)createShapeLayer:(UIView *)view
{
shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.lineCap = kCALineCapRound;
shapeLayer.lineJoin = kCALineJoinRound;
shapeLayer.lineWidth = 10.0;
[view.layer addSublayer:shapeLayer];//view.layer
return shapeLayer;
}
你似乎有编程想通了。其余的只是基本的数学。有机会重复三角(正弦,余弦,正切)。 –