我想允许用户绘制曲线,使得任何线都不能穿过另一条线甚至自身.绘制曲线是没有问题的,我甚至发现我可以通过追踪线的节点向前和向后然后关闭路径来创建一个闭合的路径,并且仍然是线条状的.
不幸的是,iOS只提供了一个测试点是否包含在一个封闭的路径中(containsPoint:和CGPathContainsPoint).不幸的是,用户可以非常容易地移动他们的手指足够快以使触摸点落在现有路径的两侧而实际上不被该路径包含,因此测试触摸点是非常没有意义的.
我找不到任何"路口"的路径方法.
关于如何完成这项任务的任何其他想法?
self.myPath=[UIBezierPath bezierPathWithArcCenter:center
radius:200
startAngle:0
endAngle:180
clockwise:YES];
Run Code Online (Sandbox Code Playgroud)
(这让我能够通过一些网络搜索来运行起来).
我有这条路.现在我想填补这条路径的反面,所以留下这部分并填充其他所有内容.我怎样才能完成编码?我对此没有太多信息.
在使用Cemal之后它显示的区域之前它只显示了一个带红色笔划的圆圈.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
self.punchedOutPath =
[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 400, 400)];
self.fillColor = [UIColor redColor];
self.alpha = 0.8;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[[self fillColor] set];
UIRectFill(rect);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(ctx, kCGBlendModeDestinationOut);
[[self punchedOutPath] fill];
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
}
Run Code Online (Sandbox Code Playgroud)
我想动画一条弯曲成bezier曲线的直线(从"_"到"n"),是否有一个可以帮助我完成它的库?
我知道如何使用UIBezierPath绘制Bezier曲线,我可以快速重绘并逐步进行转换,但是如果已经做了某些事情就会很酷:-)
我一直UIBezierPath
用Swift 做一个简单的动画.此路径包括创建带有彩色边框的圆角矩形.动画必须是彩色边框的绘图.为此,我创建了一个CAShapeLayer
带有UIBezierPath(roundedRect:, cornerRadius: )
let layer = CAShapeLayer()
var viewPrueba = UIView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
viewPrueba = UIView(frame: CGRectMake(self.view.frame.width/2-100, self.view.frame.height/2 - 100, 200, 200))
self.view.addSubview(viewPrueba)
let path = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 40.0)
layer.path = path.CGPath
layer.fillColor = UIColor.clearColor().CGColor
layer.strokeColor = UIColor.blueColor().CGColor
layer.strokeStart = 0.0
layer.strokeEnd = 0.0
layer.lineWidth = 4.0
layer.lineJoin = kCALineJoinRound
viewPrueba.layer.addSublayer(layer)
let tapGR = …
Run Code Online (Sandbox Code Playgroud) 我正在向ARSCNSceneView场景添加多个透明SCNShape对象.
问题是重叠的形状是非常明显的,我希望它显示为一个单一的形状 - 所有形状的结合.
失败的方法:
我在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条原始路径.
我想创造不同的形状.下图是一个例子.你能告诉我如何塑造不同的形状吗?
ios ×10
uibezierpath ×10
bezier ×2
objective-c ×2
swift ×2
animation ×1
arkit ×1
cashapelayer ×1
cgcontext ×1
cocoa-touch ×1
hittest ×1
iphone ×1
nsbezierpath ×1
scenekit ×1
stroke ×1