我在touchesMoved中通过UIBezierPath绘制一个形状.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
secondPoint = firstPoint;
firstPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
CGPoint mid1 = midPoint(firstPoint, secondPoint);
CGPoint mid2 = midPoint(currentPoint, firstPoint);
[bezierPath moveToPoint:mid1];
[bezierPath addQuadCurveToPoint:mid2 controlPoint:firstPoint];
[self setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
我想在closePath之后填充其中的RED颜色但不能.请帮忙!
- (void)drawRect:(CGRect)rect
{
UIColor *fillColor = [UIColor redColor];
[fillColor setFill];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
[bezierPath closePath];
[bezierPath fill];
[bezierPath stroke];
}
Run Code Online (Sandbox Code Playgroud) 我想画一个用来表示进展的圆圈.进度更新可能会很快进行,我想对圆圈的更改进行动画处理.
我已尝试使用以下方法执行此操作,但似乎没有任何工作.这可能吗?
- (id)initWithFrame:(CGRect)frame strokeWidth:(CGFloat)strokeWidth insets:(UIEdgeInsets)insets
{
if (self = [super initWithFrame:frame])
{
self.strokeWidth = strokeWidth;
CGPoint arcCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = CGRectGetMidX(self.bounds) - insets.top - insets.bottom;
self.circlePath = [UIBezierPath bezierPathWithArcCenter:arcCenter
radius:radius
startAngle:M_PI
endAngle:-M_PI
clockwise:YES];
[self addLayer];
}
return self;
}
- (void)setProgress:(double)progress {
_progress = progress;
[self updateAnimations];
}
- (void)addLayer {
CAShapeLayer *progressLayer = [CAShapeLayer layer];
progressLayer.path = self.circlePath.CGPath;
progressLayer.strokeColor = [[UIColor whiteColor] CGColor];
progressLayer.fillColor = [[UIColor clearColor] CGColor];
progressLayer.lineWidth = self.strokeWidth;
progressLayer.strokeStart = 10.0f;
progressLayer.strokeEnd …
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我在其中使用UIBezierPath并通过一系列appendPath:调用将其用作画笔.经过一些事情,并且具有非常复杂的刷子形状,内存耗尽,应用程序停止运行.我真正想做的是完全一样的联盟,就像Paint Code一样,但我找不到任何方法这样做.
我如何加入两个或更多UIBezierPaths?
编辑:
这是我想要动态实现的视觉效果.
在Paint Code中,您将采用两条路径并将它们重叠,如下所示:
但我想将它们合并/合并为一个新的单一路径,如:
请注意,在Paint Code的底部面板中,现在有一个单一形状的代码,这就是我希望能够以编程方式获得1000条原始路径.
我正试图为我的观点制作圆角并解决一个奇怪的问题.
我使用以下代码为我的视图制作圆角
bezierPath = [UIBezierPath bezierPathWithRoundedRect:btnView.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:radius];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = btnView.bounds;
maskLayer.path = bezierPath.CGPath;
btnView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)
问题是,它不适用于底角.如果我UIRectCornerBottomLeft
没有使用任何事情,如果我UIRectCornerAllCorners
只使用顶角是圆的.
编辑:我不使用layer.cornerRadius因为我只想圆底角.
事实证明,如果我UIViewAutoresizingFlexibleHeight
从视图中删除自动调整遮罩,我没有问题.但我想使用autoresizing mask.有可能,如果是的如何?
我已经尝试在设置图层蒙版之前和之后设置autoresizingMask.没运气!
我写了一些代码来创建一个UIImage
具有UIBezierPath
,但没有奏效.有人可以帮我找出我的代码有什么问题.
-(UIImage*) drawTriangle{
CGRect rect = CGRectMake(0.0, 0.0, 30.0, 30.0);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
UIBezierPath *bezier = [UIBezierPath bezierPathWithRect:rect];
[bezier moveToPoint:CGPointMake(25, 5)];
[bezier addLineToPoint:CGPointMake(5, 15)];
[bezier addLineToPoint:CGPointMake(25, 25)];
[bezier setLineWidth:3.0];
[bezier setLineJoinStyle:kCGLineJoinBevel];
[bezier stroke];
CGContextAddPath(context, bezier.CGPath);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsPopContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud) 基本上我需要有一个不同颜色的笔划圆,大小相等.例如,1/2是蓝色,1/2是红色.图片(对不起这么糟糕的图片):
我怎么画这样的东西?
我有一个UIBezierPath
,我想得到它的镜像.我怎么能做到这一点?
// Method for generating a path
UIBezierPath *myPath = [self generateAPathInBounds:boundingRect];
// ? now I would like to mirror myPath ?
Run Code Online (Sandbox Code Playgroud) 我有一个UIView,它作为子视图添加到我的视图控制器.我在这个观点上画了一条更好的路径.我的drawRect实现如下
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *bpath = [UIBezierPath bezierPath];
[bpath moveToPoint:CGPointMake(50, 50)];
[bpath addLineToPoint:CGPointMake(100, 50)];
[bpath addLineToPoint:CGPointMake(100, 100)];
[bpath addLineToPoint:CGPointMake(50, 100)];
[bpath closePath];
CGContextAddPath(context, bpath.CGPath);
CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 2.5);
CGContextStrokePath(context);
UIColor *fillColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.5 alpha:0.7];
[fillColor setFill];
[bpath fill];
}
Run Code Online (Sandbox Code Playgroud)
我希望在这个bezier路径中检测tap,但不是在UIView内部和路径外部的点.例如,在这种情况下,如果我的触摸坐标是(10,10),则不应检测到它.我知道CGContextPathContainsPoint但是当触摸在路径内时它没有帮助.有没有办法检测bezier路径内的触摸事件?
我使用UIBezierPath和CAShapeLayer在iOS中编码了半圈.
clockWiseLayer = [[CAShapeLayer alloc] init];
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = M_PI + M_PI_2;
CGFloat width = CGRectGetWidth(imageView.frame)/2.0f + 30;
CGFloat height = CGRectGetHeight(imageView.frame)/2.0f +50;
CGPoint centerPoint = CGPointMake(width, height);
float radius = CGRectGetWidth(imageView.frame)/2+10;
clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES].CGPath;
clockWiseLayer.fillColor = [UIColor clearColor].CGColor;
clockWiseLayer.strokeColor = [UIColor blueColor].CGColor;
clockWiseLayer.borderColor = [UIColor greenColor].CGColor;
clockWiseLayer.backgroundColor = [UIColor redColor].CGColor;
clockWiseLayer.strokeStart = 0.0f;
clockWiseLayer.strokeEnd = 0.5f;
clockWiseLayer.lineWidth = 2.0f;
clockWiseLayer.borderWidth = 5.0f;
clockWiseLayer.shouldRasterize = NO;
[self.layer …
Run Code Online (Sandbox Code Playgroud) iPhoneX的不寻常的底角是Apple的新版(2017年)"iPhoneX的连续角落".
对于任何有经验的iOS程序员来说,接近曲线绝对是微不足道的,但是:
Apple没有解释这一点似乎非常奇怪.
重复,
对于任何有经验的iOS程序员来说,接近曲线是绝对微不足道的.
这里要问的问题具体是苹果实际上如何做到这一点?
拜托,拜托,请不要再发布任何答案,向初学者展示如何绘制曲线和近似iPhone曲线.
ios ×10
uibezierpath ×10
objective-c ×3
cashapelayer ×2
angle ×1
drawrect ×1
iphone ×1
iphone-x ×1
uiimage ×1
uiview ×1