gpt4 book ai didi

ios - 如果绘制新线,如何删除线

转载 作者:行者123 更新时间:2023-11-29 11:58:47 25 4
gpt4 key购买 nike

大家好请任何人解决问题我可以在 UIImageView 上画线但是如果画新线我需要删除现有线...

if(selectBtnTag.tag==111)
{
[self selectedButtonBg:selectBtnTag];
// [self selectBtncolor_Action:@"111" :self.btn_wagonwheel :0];
//[self.img_pichmap setImage:[UIImage imageNamed:@"WagonWheel_img"]];
_View_Appeal.hidden=YES;
_view_Wagon_wheel.hidden=NO;



_View_Appeal.hidden=YES;
self.view_bowlType.hidden = YES;
self.view_fastBowl.hidden = YES;
self.view_aggressiveShot.hidden = YES;
self.view_defensive.hidden = YES;
self.img_pichmap.hidden=YES;
self.PichMapTittle.hidden=YES;

if(IS_IPAD_PRO)
{
self.height.constant=450;
self.width.constant=450;
}
else{
self.height.constant=350;
self.width.constant=350;
}

if([self.BatmenStyle isEqualToString:@"MSC012"])
{
[self.img_WagonWheel setImage:[UIImage imageNamed:@"LHWagon"]];
}
else{
[self.img_WagonWheel setImage:[UIImage imageNamed:@"RHWagon"]];
}

if (IS_IPAD_PRO) {
self.centerlbl=[[UILabel alloc]initWithFrame:CGRectMake(self.img_WagonWheel.frame.size.width/2+46, self.img_WagonWheel.frame.size.width/2+11, 5, 5)];
}
else

self.centerlbl=[[UILabel alloc]initWithFrame:CGRectMake(self.img_WagonWheel.frame.size.width/2-3, self.img_WagonWheel.frame.size.width/2-30, 5, 5)];

[self.centerlbl setBackgroundColor:[UIColor clearColor]];
[self.img_WagonWheel addSubview:self.centerlbl];

UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickWagonWheelmapTapAction:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired=1;
tapRecognizer.delegate=self;
[self.view_DrawlineWagon addGestureRecognizer:tapRecognizer];
[self.view_DrawlineWagon setUserInteractionEnabled:YES];
self.view_bowlType.hidden = YES;
self.view_fastBowl.hidden = YES;
self.view_aggressiveShot.hidden = YES;
self.view_defensive.hidden = YES;


}
}




-(void)didClickWagonWheelmapTapAction:(UIGestureRecognizer *)wagon_Wheelgesture
{
CGPoint p = [wagon_Wheelgesture locationInView:self.img_WagonWheel];
float Xposition = p.x;
float Yposition = p.y;
CGMutablePathRef straightLinePath = CGPathCreateMutable();
CGPathMoveToPoint(straightLinePath, NULL, Xposition, Yposition);
CGPathAddLineToPoint(straightLinePath, NULL,self.centerlbl.center.x,self.centerlbl.center.y);

// CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),self.backgroundColor.CGColor);
//
// CGContextFillRect(UIGraphicsGetCurrentContext(), rect);


CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = straightLinePath;
UIColor *fillColor = [UIColor redColor];
shapeLayer.fillColor = fillColor.CGColor;
UIColor *strokeColor = [UIColor redColor];
shapeLayer.strokeColor = strokeColor.CGColor;
shapeLayer.lineWidth = 2.0f;
shapeLayer.fillRule = kCAFillRuleNonZero;


[self.img_WagonWheel.layer addSublayer:shapeLayer];


}

enter image description here

你可以在这里看到我的图片我可以画多条线但是如果我画新线我需要画一条线,现有的线需要删除请任何人帮助我解决这个问题。

提前致谢

最佳答案

像这样更改您的UIGestureRecognizer 方法

-(void)didClickWagonWheelmapTapAction:(UIGestureRecognizer *)wagon_Wheelgesture {

for (CALayer *layer in self.img_WagonWheel.layer.sublayers) {
if ([layer.name isEqualToString:@"DrawLine"]) {
[layer removeFromSuperlayer];
break;
}
}
CGPoint p = [recognizer locationInView:self.imgDraw];
float Xposition = p.x;
float Yposition = p.y;
CGMutablePathRef straightLinePath = CGPathCreateMutable();
CGPathMoveToPoint(straightLinePath, NULL, Xposition, Yposition);
CGPathAddLineToPoint(straightLinePath, NULL,self.view.center.x,self.view.center.y);
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = straightLinePath;
UIColor *fillColor = [UIColor redColor];
shapeLayer.fillColor = fillColor.CGColor;
UIColor *strokeColor = [UIColor redColor];
shapeLayer.strokeColor = strokeColor.CGColor;
shapeLayer.lineWidth = 2.0f;
shapeLayer.fillRule = kCAFillRuleNonZero;
shapeLayer.name = @"DrawLine";
[self.imgDraw.layer addSublayer:shapeLayer];
}

希望对你有帮助

关于ios - 如果绘制新线,如何删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com