- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我试图在平移手势发生的地方画一条线。问题是当我尝试使用这段代码时
var firstPoint: CGPoint!
var path: UIBezierPath!
@IBAction func panned(gesture: UIPanGestureRecognizer) {
switch gesture.state {
case .Began: firstPoint = gesture.locationOfTouch(0, inView: view)
case .Ended: gesture.cancelsTouchesInView = true
case .Changed:
path.moveToPoint(firstPoint)
path.addLineToPoint(gesture.translationInView(view))
path.stroke()
default: break
}
}
...我收到多个错误,我不太确定该怎么办。
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSetLineWidth: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSetLineJoin: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSetLineCap: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSetMiterLimit: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextSetFlatness: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Apr 2 17:40:03 MacBook-Pro.local Paint[6729] <Error>: CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
最佳答案
这告诉您您正在尝试在有效上下文(CGContextRef
)之外调用 CoreGraphics 函数。你不应该调用 stroke
除非你在 UIView
子类的 drawRect
中或者在 UIGraphicsBeginImageContextWithOptions
和 UIGraphicsEndImageContext
(或类似的东西)。但是,如果您不在图形上下文中,则不能只描边
路径。
如果你只是想将这个路径添加到一个UIView
,你也可以创建一个CAShapeLayer
,并使用这个贝塞尔曲线的cgPath
路径,并获取生成的 CAShapeLayer
并将其添加为 View 层的子层。例如,在 Swift 3 及更高版本中:
var drawPath: UIBezierPath!
var shapeLayer: CAShapeLayer!
func handlePan(gesture: UIPanGestureRecognizer) {
let location = gesture.location(in: gesture.view)
if gesture.state == .began {
drawPath = UIBezierPath()
drawPath.move(to: location)
shapeLayer = CAShapeLayer()
shapeLayer.strokeColor = UIColor.black.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = 4.0
gesture.view?.layer.addSublayer(shapeLayer)
} else if gesture.state == .changed {
drawPath.addLine(to: location)
shapeLayer.path = drawPath.cgPath
}
}
关于swift - 使用 UIBezierPath 获取 "invalid context"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29423060/
我有两个 UIBezierPath,一个表示图像的多边形部分,另一个是要在其上绘制的路径。 我需要找到它们之间的交点,以便只有在这个交点区域内的点才会被着色。 UIBezierPath 中是否有一种方
我正在制作一个应用程序,允许用户用手指在屏幕上绘制不同的颜色。图纸是用 UIBezierPaths 绘制的,但我需要橡皮擦。我确实有一个橡皮擦,它只是一条以背景图像为颜色的路径,但这种方法会导致内存问
我想用 SceneKit 画一条贝塞尔曲线,并认为这会起作用: func drawCurvedLine() { let scene = SCNScene() let scnView =
我在设置为 iPhone (Retina 4-inch) 的模拟器中运行此代码 -(void)drawRect:(CGRect)rect { [[UIColor whiteColor]set]
我想绘制月亮,然后为月亮的阴影设置动画。但启动此代码后,我可以在动画线上看到一些故障: GIF: 为什么会发生这种情况? Playground 代码 here 更新1:此函数创建的两条路径具有不同的角
假设我们有一个 UIBezierPath...它的边界是完全正方形的...像这样: func getExponentPath(rotate180: Bool) -> UIBezierPath {
我想绘制月亮,然后为月亮的阴影设置动画。但启动此代码后,我可以在动画线上看到一些故障: GIF: 为什么会发生这种情况? Playground 代码 here 更新1:此函数创建的两条路径具有不同的角
假设我们有一个 UIBezierPath...它的边界是完全正方形的...像这样: func getExponentPath(rotate180: Bool) -> UIBezierPath {
我正在试验 UIBezierPath。我想做一个 GridView 。 NSInteger yAxisIncremental = 0; NSInteger xAxisIncremental = 0;
我需要使用bezeirPath绘制此形状: 我做了以下事情: 我创建了矩形路径。 然后我添加了五个圈子。 如下面的代码所示: let stickLayerBezeirPath = UIBezierPa
我将 Apple 文档阅读到 UIBezierPath目的。我是否正确理解它不支持相对路径? 我正在尝试将此 svg 路径转换为 UIBezierPath: // svg path m90 36c
我正在尝试制作一个球从用户画线反弹的游戏。绘制线的代码包含在下面并且可以正常工作,但是一旦球与它接触或玩家画一条新线,我将如何删除线? path = [UIBezierPath bezierPath]
我想画一条这样的路径: 这就是我写的: CGFloat radius = 50; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveT
我在 View 中有一个 UIBezierPath 。我想在单击形状时显示警报,但实际发生的情况是,不仅在我单击形状时显示警报,而且当我单击 View 中的任意位置时也会显示警报。 如何更改此代码,以
我正在尝试从圆形到带圆角的正方形制作动画。据我了解,对于流畅的动画,两条路径的点数应该相等。所以我写了一个基于多条弧构建圆的函数: private func circleShape(segmentNu
对于横向和纵向模式,是否可以将元素重置到相同的%位置(距x = 0轴的距离)?如果是的话你能告诉我怎么做吗?另外,由于我是 Swift 的新手,如果您发现任何错误的代码错误,请DO通知我以便得到更好的
我正在尝试在叠加渲染器中使用 UIBezierPath 绘制一些线条。我收到错误 CGContextSetStrokeColorWithColor: invalid context 0x0 我怀疑这是
我想圆化我的右角,但只适用于左角 let path = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [UIRectCorner.
我想圆化我的右角,但只适用于左角 let path = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: [UIRectCorner.
当我尝试平移路径,将其移动到原点 {0, 0} 时,生成的路径边界错误。 (或者,我的假设是错误的)。 例如该路径给出以下边界信息: let bezier = UIBezierPath(cgPath:
我是一名优秀的程序员,十分优秀!