- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 swift 2.2,我正在处理这样的问题:我有一组 UIBezier 对象,我需要为它们创建一个笔划作为一条路径。
我曾经有一个特殊的功能,但这种方法的优点是它创建了多个层。这符合我的要求,因为我需要一层
func createStroke(line: UIBezierPath) {
self.currentPath = CAShapeLayer()
currentPath.path = line.CGPath
currentPath.strokeColor = UIColor.blackColor().CGColor
currentPath.fillColor = UIColor.clearColor().CGColor
currentPath.lineWidth = 1
self.view.layer.addSublayer(currentPath)
}
从贝塞尔曲线数组创建多路径的最佳方法是什么?第一个想法是创建一个 for 循环,但我认为这不是一个干净的方法。
最佳答案
你可以这样做(这是 playground 代码):
let myView = UIView(frame:CGRect(x: 100, y: 100, width: 250, height: 250))
myView.backgroundColor = UIColor.white
let myLayer = CAShapeLayer()
func createPath(i: Int) -> UIBezierPath {
let path = UIBezierPath()
path.move(to: CGPoint(x: 2*i, y: 9*i - 4))
path.addLine(to: CGPoint(x: 10 + 5*i, y: 20 + 4*i))
return path
}
func createStroke(line: UIBezierPath) {
myLayer.path = line.cgPath
myLayer.strokeColor = UIColor.black.cgColor
myLayer.fillColor = UIColor.black.cgColor
myLayer.lineWidth = 1
}
let paths = [createPath(i: 0), createPath(i: 15), createPath(i: 8), createPath(i: 10)]
let myPath = UIBezierPath()
for path in paths {
myPath.append(path) // THIS IS THE IMPORTANT PART
}
createStroke(line: myPath)
myView.layer.addSublayer(myLayer)
myView
这是它在 Playground 上的样子:
这样你只有一层
关于arrays - 如何从多个 BezierPath 创建多个路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42091599/
我正在尝试根据每个像素的透明度使用BezierPath绘制图像的轮廓。。然而,我对逻辑有一个问题;我的逻辑也画出了内部轮廓。。我只想用BezierPath绘制外部轮廓。我得到的(第一个形状是原始图像,
我将以下代码放在 UIViewController 中: - (void)drawRect:(CGRect)rect { UIBezierPath *trackPath = [UIBezier
我在 Objective-C 中绘制了一个 UIBezierPath 并用红色填充它。现在,我想根据百分比用多种颜色填充路径。例如:我想用 20% 的绿色填充路径,用红色填充剩余的 80%,彼此叠加(
我正在使用 UIbezierpath 为我的项目绘图。我正在使用颜色来绘制。当我在相同的点上绘制时,颜色会变暗。(即通常会在同一个地方绘制)。我想在覆盖时保持画笔颜色。 任何帮助将不胜感激!!!! 最
我想将 UIBezierPath 设置为 View 中的掩码:目标是这样的: 所以我用框架绘制 View : CGFloat round = 80; UIView *myView = [[UIView
嗨,我有一个路径(形状)和一个高分辨率图像。我将高分辨率图像设置为在我绘制路径的 View 内的 AspectFit,我想用路径掩盖图像,但以图像的全分辨率,而不是我们看到路径的分辨率。问题是,当我不
我想要完成什么this demo does但对于iOS。本质上,描边一条路径并在描边时填充它,没有闭合线。 我现在的方法是在 touchesMoved 上,将 CGPath 变量移动到前一个点,并划一
这个问题已经有答案了: How to draw a circle path with color gradient stroke (4 个回答) 已关闭 6 年前。 我读过一些主题,但不适用于我...
我正在尝试沿任意路径为按钮设置动画。为此,我需要创建一个路径,我正在使用 BezierPath。 但是,每当我将 moveToPoint 设置为 0,0 而不是从屏幕左上角开始动画时,就会发生一些奇怪
我想重新创建 AppStore 的“今日”卡片,其中包含圆角和浅色阴影。 我创建了一个路径、一个 maskLayer 和一个单独的 shadowLayer,根据多个消息来源,这是实现它的方式。 然而,
我有一个 tableView 单元格,它有一个 ImageView 。对于这个 View ,我创建了 UIImage 扩展,我在其中使用 bezierPath 2 矩形绘制,然后,我从这个绘图中制作了
我正在使用 swift 2.2,我正在处理这样的问题:我有一组 UIBezier 对象,我需要为它们创建一个笔划作为一条路径。 我曾经有一个特殊的功能,但这种方法的优点是它创建了多个层。这符合我的要求
我有一个包含CGPoints的NSArray,并绘制了从此类返回的路径。问题是[bezierPath closePath]不会关闭此类中的路径。这是为什么?我需要使用此类给我的曲线将端点连接到数组的第
我试图在 UIView 容器内(底部)添加贝塞尔路径(三角形),但是我似乎无法正确理解 UIView 容器的要点。我得到这个结果(其中似乎有一条三角形显示在容器 View 的左侧): 我想要一个输出,
我不知道以下情况: 我从 PaintCode 导出了一个 NSObject 并创建了一个 .swift 文件 (someObject.swift)。 public class PlanATrip: N
我正在尝试检测 UIView 中 BezierPaths 内的 Tap,并发现许多对 containsPoint 方法的引用。但是我似乎无法找到如何从我的 ViewController 中实际引用 B
我正在绘制 BezierPath on Touch 事件。现在我必须使用手势方法在同一位置旋转贝塞尔路径。但问题是,旋转后其位置发生变化。它看起来像下图。我该如何解决这个问题? 上图为原图。与我分享你
我想加载一个包含 uibezierPath 的类的实例,并在应用程序启动时重绘这些先前的路径。字典返回正确的实例,但我无法绘制路径: View 是在 Storyboard中创建的,所以我使用了 ini
我尝试将 uiimageview 的顶部两个角圆化,但以下代码不显示圆角,只显示普通图像。我错过了什么吗?谢谢 UIImageView * imgView = [[UIImageVie
我正在努力实现 https://github.com/joshdhenry/SpinWheelControl我的应用程序中的库,对于每个轮子切片,我试图将自定义图像添加到它的 shapelayer,或
我是一名优秀的程序员,十分优秀!