2016-08-24 60 views
0

我使用此代码在屏幕上绘制触摸路径,但随着屏幕尺寸的增加,触摸路径不稳定。任何人都可以提供一个建议吗?随着屏幕尺寸的增大,屏幕上的触摸屏路径也在缩小

路径绘制在6S

路径上绘制4S

func draw(start: CGPoint, end: CGPoint){ 

    UIGraphicsBeginImageContext(self.subImageView.frame.size) 
    let context = UIGraphicsGetCurrentContext() 
    subImageView?.image?.drawInRect(CGRect(x: 0, y: 0, width: subImageView.frame.width, height: subImageView.frame.height)) 
    CGContextSetLineWidth(context, 6) 
    CGContextBeginPath(context) 
    CGContextMoveToPoint(context, start.x, start.y) 
    CGContextAddLineToPoint(context, end.x, end.y) 
    CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor) 
    CGContextStrokePath(context) 
    let newImage = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 
    subImageView.image = newImage 

} 
+0

请再次添加图片请 –

回答

0

可能由以下事实,即4S屏幕为2倍,而on6S屏幕3x.Due的方式,你造成的创建你的图像上下文,图像没有考虑到这一点,并始终有1倍的大小。 尝试使用UIGraphicsBeginImageContextWithOptions(self.subImageView.frame.size, false, 0.0)而不是UIGraphicsBeginImageContext(self.subImageView.frame.size)

+0

非常感谢! – John

+0

@John如果能解决你的问题,你能接受吗? – hybridcattt