标签: uibezierpath

如何在UIBezierPath中填充颜色?

我在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)

ios uibezierpath

12
推荐指数
1
解决办法
2万
查看次数

为CAShapeLayer设置动画以绘制进度圆

我想画一个用来表示进展的圆圈.进度更新可能会很快进行,我想对圆圈的更改进行动画处理.

我已尝试使用以下方法执行此操作,但似乎没有任何工作.这可能吗?

- (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)

core-animation objective-c cashapelayer ios uibezierpath

12
推荐指数
1
解决办法
1万
查看次数

联盟UIBezierPaths而不是Apend路径

我有一个应用程序,我在其中使用UIBezierPath并通过一系列appendPath:调用将其用作画笔.经过一些事情,并且具有非常复杂的刷子形状,内存耗尽,应用程序停止运行.我真正想做的是完全一样的联盟,就像Paint Code一样,但我找不到任何方法这样做.

我如何加入两个或更多UIBezierPaths?

编辑:

这是我想要动态实现的视觉效果.

在Paint Code中,您将采用两条路径并将它们重叠,如下所示:

但我想将它们合并/合并为一个新的单一路径,如:

Paint Code中的合并路径

请注意,在Paint Code的底部面板中,现在有一个单一形状的代码,这就是我希望能够以编程方式获得1000条原始路径.

core-graphics ios uibezierpath

12
推荐指数
1
解决办法
2740
查看次数

UIBezierPath不会绘制圆角底角

我正试图为我的观点制作圆角并解决一个奇怪的问题.

我使用以下代码为我的视图制作圆角

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.没运气!

iphone rounded-corners uiview ios uibezierpath

11
推荐指数
2
解决办法
8319
查看次数

如何使用UIBezierPath创建UIImage

我写了一些代码来创建一个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)

uiimage ios uibezierpath

11
推荐指数
3
解决办法
2万
查看次数

UIBezierPath绘制具有不同笔划的圆

基本上我需要有一个不同颜色的笔划圆,大小相等.例如,1/2是蓝色,1/2是红色.图片(对不起这么糟糕的图片):

例

我怎么画这样的东西?

drawrect ios uibezierpath

11
推荐指数
1
解决办法
1万
查看次数

如何镜像UIBezierPath?

我有一个UIBezierPath,我想得到它的镜像.我怎么能做到这一点?

 // Method for generating a path
 UIBezierPath *myPath = [self generateAPathInBounds:boundingRect];

 // ? now I would like to mirror myPath ?
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c ios uibezierpath

11
推荐指数
1
解决办法
3465
查看次数

检测bezier路径内的水龙头

我有一个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路径内的触摸事件?

core-graphics objective-c ios uibezierpath

11
推荐指数
3
解决办法
6884
查看次数

UIBezierPath的开始和结束角度?

我使用UIBezierPathCAShapeLayer在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)

angle cashapelayer ios uibezierpath

11
推荐指数
2
解决办法
9375
查看次数

实际上复制/提取Apple的"iPhoneX的连续角落"?

iPhoneX的不寻常的底角是Apple的新版(2017年)"iPhoneX的连续角落".

对于任何有经验的iOS程序员来说,接近曲线绝对是微不足道的,但是:

有没有人确切知道如何实现这些,就像Apple一样?

即使是私人电话,也不例外.

Apple没有解释这一点似乎非常奇怪.

在此输入图像描述

请注意,曲线"近似"是微不足道的:

重复,

  1. 对于任何有经验的iOS程序员来说,接近曲线绝对微不足道.

  2. 这里要问问题具体是苹果实际上如何做到这一点?

拜托,拜托,请不要再发布任何答案,向初学者展示如何绘制曲线和近似iPhone曲线.

ios uibezierpath iphone-x

11
推荐指数
1
解决办法
939
查看次数