Tag: uibezierpath

EXC_BAD_ACCESS,同时使用CoreAnimation

我使用CoreAnimation来animationUIImageView(曲线贝塞尔animation)。 这里是我的代码: CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationCubic; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; CGPoint endPoint = originalPosition; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:star.layer.position]; [path addQuadCurveToPoint:endPoint controlPoint:CGPointMake(star.layer.position.x, endPoint.y)]; pathAnimation.path = path.CGPath; [star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"]; 结果,我得到了stacktrace的EXC_BAD_ACCESS(code = 2,address = 0x0) : CoreGraphics`CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const: 0x613c06: pushl %ebp 0x613c07: movl […]

在Swift中绘制人造物

下面的代码通过覆盖触摸来绘制线条,但是在绘制时存在一个人造物,见下图。 当改变方向而锯齿形在屏幕上蜿蜒的时候,有时线会变成一个平坦的直angular,而不是保持圆形。 当在小圆点上画点时也会出现人为现象,当手指离开屏幕时,绘图点有时会半圈闪烁半圈,部分圈残留。 人工制品是间歇性的,而不是完全一致或可预测的模式,这使得很难在代码中find问题。 它出现在模拟器和iOS7 – iOS9的设备上。 一个包含两个带有Xcode项目绘制点和线的video屏幕截图的zip文件被上传到一个名为Archive.zip(23MB)的DropBox文件中https://www.dropbox.com/s/hm39rdiuk0mf578/Archive.zip?dl = 0 问题: 1 – 在代码中,是什么造成了这个点/半圆的人造物,怎样才能纠正? class SmoothCurvedLinesView: UIView { var strokeColor = UIColor.blueColor() var lineWidth: CGFloat = 20 var snapshotImage: UIImage? private var path: UIBezierPath? private var temporaryPath: UIBezierPath? private var points = [CGPoint]() private var totalPointCount = 0 override func drawRect(rect: CGRect) { snapshotImage?.drawInRect(rect) strokeColor.setStroke() […]

适合UIBezierPath / CGPath圈

我需要将任意形状的pathassembly到一个圆的内部。 我可以通过计算大小,构build目标矩形,然后缩放path以适合目标矩形,来适应圆的矩形path。 let targetSize = circleDiameter / sqrt(2) let destRect = CGRect(x: 0, y: 0, width: targetSize, height: targetSize) // … Scale the path to the rect, using boundingBox of path. 但是扩展过程不是问题; 这真的是如何计算所需的规模。 基于边界框的方法对于非矩形形状提供了很差的适应性,并且对于诸如圆形的形状很不适合。 任何人都可以提出一种方法来适应任何一个圆的内部path? 谢谢。 [编辑 – 以后大量的研究] 在这个图像中可以看到问题: 蓝色矩形表示原始图像,修剪到path。 红色圆圈是最小的边界圆。 绿色矩形表示边界圆的边界框。 我需要计算红圈,所以我可以用它来缩放path。 原来这就是所谓的最小包围圆问题(AKA最小的围合圆)。 唉,我找不到任何已知algorithm的Swift或Objective-C实现,并可能需要解决一些Java / JS / C ++代码。 如果有人能节省我的时间,请做! 温暖的模糊入境。 [另一个编辑,时间飞逝] 从中国的angular度来看,这是一个相当“有趣”的问题。 […]

UIBezierPath在滚动时出现问题

我是iOS新手。 我正在做一个聊天应用程序。 我正在使用UITableView来显示消息聊天(一个单元格 – 一个消息)。 在每个单元格中,我将在2,3或4个angular落(比如Facebook聊天) 为了更圆润,我使用每个Tableview Cell layoutSubView中的UIBezierPath UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(3.0, 3.0)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.bounds; maskLayer.path = maskPath.CGPath; self.messageView.layer.mask = maskLayer; 问题是 ,当布局第一次初始,一切工作正常,但是当我滚动一些单元格有错误的rounder(我找出问题是有时滚动self.messageView.bounds返回错误的值,所以UIBezierPath绘制错误的angular落),但我不'不知道为什么 我怎样才能防止它发生? 或者我可以有另一种方式来rounder视图没有UIBezierPath (谷歌,但我只能find一种方法来圆的UIView是使用UIBezierPath :()? 任何帮助,将不胜感激

是否有可能从uview中获得所有uibezerpath?

我一直在研究,没有find答案。 如果我使用CGGontext绘制到视图,是否有可能从UIView一次绘制UIView所有的UIBezierPath? (如果是的话,你可以给我一个想法如何?)UIBezierPath来自用户input,所以如果用户绘制了很多UIBezierPath,我需要所有这些path,并将其保存到.svg文件。

通过画一条线来连接UIButtons

我需要连接这些button,但有问题,你可以在截图中看到。 我需要最后一行垂直(绿色圆圈)。 有什么build议么? 这里是代码: @IBAction func drawButtons (sender: AnyObject) { buttonContainerView.removeFromSuperview() // Clear containerView buttonContainerView = UIView() // Create a new instance let buttonCount = array.count let n = Int(self.view.frame.size.width) / 90 //check how many buttons can fit in the screen let buttonsPerRow = n let horizontalSpace: CGFloat = 80 let verticalSpace: CGFloat = 80 […]

UIBezierpath移除问题

我正在尝试制作一个游戏,其中一个球从用户画出的线上反弹。 画线的代码包含在下面,并且工作正常,但是一旦球接触到它或者玩家画了一条新线,我将如何移除该线? path = [UIBezierPath bezierPath]; // Start Coords of Line [path moveToPoint:CGPointMake(pos2x, pos2y)]; [path addLineToPoint:CGPointMake(pos1x, pos1y)]; // End Coords of Line CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; shapeLayer.strokeColor = [[UIColor whiteColor] CGColor]; shapeLayer.lineWidth = 3.0; shapeLayer.fillColor = [[UIColor clearColor] CGColor]; [self.view.layer addSublayer:shapeLayer]; 提前致谢!

掩盖CAShapeLayer创build这个奇怪的神器?

我想为待办事项列表创build一个平滑的进度条。 我用一个圆圈(CGMutablePath)掩盖了灰色区域,并有一个明显的圆弧状伪像。 不仅如此,酒吧右侧还有一个神器。 注:我试图栅格化图层无济于事。 什么原因导致iOS做到这一点,我该如何解决这个问题或摆脱它? private var circleMask: CAShapeLayer = CAShapeLayer() override func layoutSubviews() { super.layoutSubviews() backgroundColor = GradientColor(.leftToRight, frame: self.bounds, colors: GradientFlatRed()) layer.cornerRadius = bounds.height / 2 plainProgressBar.layer.cornerRadius = layer.cornerRadius layer.shouldRasterize = true layer.rasterizationScale = UIScreen.main.scale plainProgressBar.layer.shouldRasterize = true plainProgressBar.layer.rasterizationScale = UIScreen.main.scale createMask() } private func createMask() { let path = CGMutablePath() path.addArc(center: CGPoint(x: […]

如何将图像拉伸成自定义形状(swift3)

下面的代码列表裁剪图像。 我希望图像被转换/拉伸,而不是在形状中裁剪。 所有的图像内容仍然在转换后的图像中。 它只会看起来不同。 extension UIImageView { func addMask(_ bezierPath: UIBezierPath) { let pathMask = CAShapeLayer() pathMask.path = bezierPath.cgPath layer.mask = pathMask } } let myPicture = UIImage(data: try! Data(contentsOf: URL(string:"https://scontent-iad3-1.xx.fbcdn.net/v/t31.0-8/14196150_10207770295835716_3510332720585393213_o.jpg?oh=fdb525410602f40f4735991b713e9c50&oe=596688E5")!))! let iv = UIImageView(image: myPicture) let bezierPath = UIBezierPath() bezierPath.move(to: iv.center) bezierPath.addLine(to: CGPoint(x: iv.frame.maxX, y: 0)) bezierPath.addLine(to: CGPoint(x: iv.frame.maxX, y: iv.frame.maxY)) bezierPath.addLine(to: CGPoint(x: 0, […]

UIBezierPath橡皮擦

我在iPad应用程序中使用UIBezierPath进行免费手绘。 我想为这个UIBezierPath应用橡皮擦。 但是我只想通过这条path擦除绘图。 我不能使用path颜色作为背景颜色,因为我在背景上有其他元素。 有谁能够帮助我。 以下是我的免费手绘图的代码。 – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; self.opaque = NO; lineWidths = 10; brushPattern = [UIColor greenColor]; pathArray = [[NSMutableArray alloc]init]; bufferArray = [[NSMutableArray alloc]init]; self.multipleTouchEnabled = NO; } return self; } – (void)drawRect:(CGRect)rect { for (NSMutableDictionary *dictionary in pathArray) { UIBezierPath […]