2017-02-09 39 views
0

我想让我的用户精确选择他们在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's work,我所做的所有操作都是将放大镜​​的中心点固定到左上方并取下面罩。

回答

1

我想你正在画线,然后在上面画图。最后尝试拨打drawLine

另外,缩放和平移在绘制可能将其置于屏幕外的线条时仍处于活动状态。您可能需要使用CGContextSaveGStateCGContextRestoreGState

+0

重设它们,它们听起来都很不错!我的Macbook在我的背部转动时开始更新!当我尝试过时,我会告诉你。 – ThrowingSpoon

+0

这是保存和恢复状态,使其工作。正如你所说,它一定是在其他地方定位它。 谢谢你的时间。 – ThrowingSpoon