OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iPhone X 上画线 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:34
标题: ios - 在 iPhone X 上画线

我的应用程序中的照片具有绘图功能。它适用于除 iPhone X 之外的所有设备。在 iPhone X 上,线条会随着每个手指的移动而淡化并向上移动。上部 10-20% 的视野区域效果很好。下面是画线的代码。

- (void)drawLineNew{

UIGraphicsBeginImageContext(self.bounds.size);
[self.viewImage drawInRect:self.bounds];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), self.selectedColor.CGColor);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), _lineWidth);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), previousPoint.x, previousPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);

CGContextStrokePath(UIGraphicsGetCurrentContext());
self.viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self setNeedsDisplay];}

以下是样图截图 enter image description here



Best Answer-推荐答案


经过数小时的尝试和尝试,我成功了。我写的代码是正确的,应该可以工作。唯一的问题是该drawingView(自身)的帧大小。 View 的高度是 float 的,这使得它随着每个像素向上移动。我应用了 lroundf 函数及其工作原理。
编码愉快。

关于ios - 在 iPhone X 上画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48150872/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4