我正在使用copy(strokingWithWidth:lineCap:lineJoin:miterLimit:transform :)来偏移CGPath .问题是偏移路径引入了似乎是斜接连接的各种锯齿状线.将更改设置miterLimit为0无效,使用斜角线连接也没有任何区别.
在此图像中,有原始路径(在应用之前strokingWithWidth),使用斜接连接的偏移路径,以及使用斜角连接的偏移路径.为什么不使用斜角连接有什么影响?
使用斜接的代码(注意使用CGLineJoin.round产生相同的结果):
let pathOffset = path.copy(strokingWithWidth: 4.0,
lineCap: CGLineCap.butt,
lineJoin: CGLineJoin.miter,
miterLimit: 20.0)
context.saveGState()
context.setStrokeColor(UIColor.red.cgColor)
context.addPath(pathOffset)
context.strokePath()
context.restoreGState()
Run Code Online (Sandbox Code Playgroud)
使用斜角的代码:
let pathOffset = path.copy(strokingWithWidth: 4.0,
lineCap: CGLineCap.butt,
lineJoin: CGLineJoin.bevel,
miterLimit: 0.0)
context.saveGState()
context.setStrokeColor(UIColor.red.cgColor)
context.addPath(pathOffset)
context.strokePath()
context.restoreGState()
Run Code Online (Sandbox Code Playgroud) 有没有办法获取CGPath的实际数据,所以它可以保存到文件中并在以后恢复?
是否有关于数据结构的文档?
我想把它写成一个字符串(就像一个SVG路径字符串),或者用字典对象和PList XML文件的某种方式编写,但我会把它拿走!
我有一个应用程序在a中绘制bezier曲线UIView,我需要在为Y设置值时找到X相交.首先,据我所知,没有办法直接找到一个点,UIBezierPath但你可以找到一点CGPath.
首先,如果我"抚摸"我UIBezierPath(就像我在我的代码中所做的那样)这实际上是在创建一个CGPath还是我需要采取进一步的步骤来实际将其转换为CGPath?
其次,我想通过提供Y的值来找到在X处相交的曲线.
我的目的是当用户移动滑块(分别向左或向右移动曲线)时,自动计算给定Y值的X.
我的开始显示.

当我调整滑块时会发生什么.

我希望我的显示器看起来像.

GraphView.h
#import <UIKit/UIKit.h>
@interface GraphView : UIView
{
float adjust;
int x;
int y;
}
- (IBAction)sliderChanged:(id)sender;
- (IBAction)yChanged:(id)sender;
@property (weak, nonatomic) IBOutlet UISlider *sliderValue;
@property (weak, nonatomic) IBOutlet UITextField *xValue;
@property (weak, nonatomic) IBOutlet UITextField *yValue;
@end
Run Code Online (Sandbox Code Playgroud)
GraphView.m
#import "GraphView.h"
@interface GraphView ()
@end
@implementation GraphView
@synthesize sliderValue, xValue, yValue;
- (id)initWithCoder:(NSCoder *)graphView
{
self = [super initWithCoder:graphView];
if (self) {
adjust …Run Code Online (Sandbox Code Playgroud) 我想要反转a CGPath(相对于Rect).通过这个,我的意思是我已经定义了一个CGPath,我希望得到一个CGPath概述在rect中的所有其他区域.
我一直在尝试不同的方式,现在谷歌搜索几天没有运气.我只是无法解决它!
考虑以下带定义的rect CGPath(其中green是定义的CGPath填充):

现在,我想要的东西(倒置CGPath)将产生以下内容:

具体来说,这是用于SKCropNode和SKPhysicsBodySpriteKit框架中的和,但是我使用CGPaths(并将路径存储在ivar中)为掩码节点生成多边形.
是颠倒了CGPath可能的还是其他方式?如果是这样,怎么样?
提前致谢.
使用Xcode附带的sprite kit模板,我修改场景如下:
#import "MyScene.h"
@interface MyScene ()
@property (nonatomic,strong)SKNode *floor;
@end
@implementation MyScene
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
}
return self;
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
[self removeAllChildren];
self.floor = nil;
self.floor = [SKNode node];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, nil, 0, 10);
for(int i = 2; i<self.frame.size.width; i+=2)
{
CGPathAddLineToPoint(path, nil, i, 10);
}
self.floor.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:path];
SKShapeNode *shape = [SKShapeNode node];
shape.path …Run Code Online (Sandbox Code Playgroud) 我有一个CGPath我想绘制的坐标系.这样做涉及将旧坐标系缩放到Context的坐标系上.为了这个目的,我使用CGContextConcatCTM()它确实转换所有点.但是,由于它是缩放操作,水平/垂直线宽变为.例如,在x方向上为10,但在y方向上为1,将导致垂直线的厚度是水平线的10倍.有没有办法保持翻译矩阵的易用性(例如CGAffineTransform),但不能同时缩放线宽,例如像CGPathApplyAffineTransformToPoints?
干杯
MrMage
我正在尝试建立一个界面,用户可以在屏幕上移动手指,图像列表沿路径移动。这个想法是图像中心永远不会离开路径。
我发现的大多数事情都与如何使用CGPath进行动画有关,而不是与实际使用路径作为用户移动的轨迹有关。
==更新。更好的描述==
即使用户没有在路径上移动手指,我也需要在路径上进行跟踪。
例如(图像波纹管),如果对象位于路径的开头,并且用户触摸屏幕上的任意位置并将手指从左向右移动,则我需要对象从左向右移动但遵循路径,即,沿着路径的尽头向右移动。
==结束更新
这是我绘制的路径,想象一下,我将拥有一个视图(任何图像),用户可以沿该路径触摸并拖动它,而无需在该路径上完全移动手指。如果用户从左向右移动,则图像应从左向右移动,但如果需要遵循该路径,则向上移动。

这就是我创建路径的方式:
CGPoint endPointUp = CGPointMake(315, 124);
CGPoint endPointDown = CGPointMake(0, 403);
CGPoint controlPoint1 = CGPointMake(133, 187);
CGPoint controlPoint2 = CGPointMake(174, 318);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, endPointUp.x, endPointUp.y);
CGPathAddCurveToPoint(path, NULL, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endPointDown.x, endPointDown.y);
Run Code Online (Sandbox Code Playgroud)
有什么想法我怎么能做到这一点?
我正在尝试为包含图像的 CALayer 创建蒙版。该掩码应能够使用多个路径的联合或联合的逆。就维恩图而言,这将是分离或联合否认(请在此处查看我无法发布的维恩图的图形:https : //en.wikipedia.org/wiki/Logical_connective#Common_logical_connectives)。我还在一个专门的 iOS 论坛上开始了一个线程,里面有很多图形和更多的示例代码:http : //www.raywenderlich.com/forums/viewtopic.php?f=2&t=7155
我确实成功地创建了第一个案例:多条路径的联合(分离)。
您可以将代码复制到新的单屏应用程序中进行试用(不要忘记包含 Quartz 框架):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// create a yellow background
UIView *bg = [[UIView alloc] initWithFrame:self.view.bounds];
bg.backgroundColor = [UIColor yellowColor];
[self.view addSubview:bg];
// create the layer on top of the yellow background that will be masked
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = self.view.layer.bounds;
imageLayer.backgroundColor = [[UIColor blueColor] CGColor];
// create …Run Code Online (Sandbox Code Playgroud) 我可以使用简单的SKSpriteNode绘制Rectangle.但我无法在其中绘制其他类型的图纸,如Triangle,Circle等,具有TWO SPLIT COLORS.有人建议和CGPath一起去.但我是新手,不知道画这种复杂的东西.任何人都可以通过SPRITEKIT中的MULTICOLOR说明使用这些图纸的简单方法.意思是它们的上部是一种颜色而下部是第二种颜色.更简洁地说,Shape分为两种颜色,无论是星形,矩形,三角形还是其他颜色.任何帮助将不胜感激.
谢谢 .
我正在更新swift 3的代码.我已经为swift 2中的spritekit对象创建了一个自定义路径.但是,现在我得到一个编译器错误:
Nil与预期的参数类型'Unsafe Pointer CGAffineTransform'不兼容
let offsetX = player.size.width * player.anchorPoint.x
let offsetY = player.size.height * player.anchorPoint.y
let path = CGMutablePath()
CGPathMoveToPoint(path, nil, 10 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 10 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 0 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 24 - offsetX, 16 - offsetY)
CGPathAddLineToPoint(path, nil, 28 - offsetX, 40 - offsetY)
CGPathAddLineToPoint(path, nil, 18 - offsetX, 46 - offsetY)
CGPathAddLineToPoint(path, nil, …Run Code Online (Sandbox Code Playgroud) cgpath ×10
ios ×4
objective-c ×3
sprite-kit ×3
swift3 ×2
uibezierpath ×2
algorithm ×1
calayer ×1
cashapelayer ×1
cgcontext ×1
drag ×1
ios7 ×1
memory-leaks ×1
quartz-2d ×1
quartz-core ×1
sprite ×1
stroke ×1
swift ×1