[英]Bezier Path Not Drawing on context
我正在尝试让我的用户更好地选择他们在UIImage上触摸的点。 我在左上角有一个放大的正方形,以2倍缩放显示他们触摸的位置。 它运作良好。
我正在尝试在放大区域的中心添加“十字准线”,以使选择更加清晰。
在下面的代码中,看不到任何行。
//Bulk of the magifying code
public override func drawRect(rect: CGRect) {
let context: CGContextRef = UIGraphicsGetCurrentContext()!
CGContextScaleCTM(context, 2, 2)
CGContextTranslateCTM(context, -self.touchPoint.x, -self.touchPoint.y)
drawLine(context)
self.viewToMagnify.layer.renderInContext(context)
}
//Code for drawing horizontal line of crosshair
private func drawLine(ctx: CGContext) {
let lineHeight: CGFloat = 3.0
let lineWidth: CGFloat = min(bounds.width, bounds.height) * 0.3
let horizontalPath = UIBezierPath()
horizontalPath.lineWidth = lineHeight
let hStart = CGPoint(x:bounds.width/2 - lineWidth/2, y:bounds.height/2)
let hEnd = CGPoint(x:bounds.width/2 + lineWidth/2,y:bounds.height/2)
horizontalPath.moveToPoint(hStart)
horizontalPath.addLineToPoint(hEnd)
UIColor.whiteColor().setStroke()
horizontalPath.stroke()
}
在这里我希望它是这有可能是线路正在制定,但过小或没有。
我尝试了其他方式来绘制线条,例如使用CGContextAddPath
我认为问题可能与renderInContextView
没有考虑到我的绘图有关,或者我没有正确添加到上下文的路径?
放大倍率代码基于GJNeilson的工作 ,我所做的只是将放大镜的中心点固定在左上方,然后取下遮罩。
我认为您是先画线然后在其上画图像。 尝试最后调用drawLine
。
此外,在绘制可能将其置于屏幕外的线时,比例和平移仍处于活动状态。 您可能必须使用CGContextSaveGState
和CGContextRestoreGState
重置它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.