Ios iPad Air上的Bezier曲线绘制问题
我有下面的代码,可以画曲线。用户绘制直线,触摸结束后,将显示控制手柄,用户可以将直线修改为所需曲线。它在所有iPad的IOS 6和IOS 7上运行良好。但它在IOS 8上运行的iPad Air和iPad mini 2上运行起来很奇怪。当用户将手柄拉向一个方向时,线的起点移向相反方向。这就像是反向坐标计算Ios iPad Air上的Bezier曲线绘制问题,ios,bezier,Ios,Bezier,我有下面的代码,可以画曲线。用户绘制直线,触摸结束后,将显示控制手柄,用户可以将直线修改为所需曲线。它在所有iPad的IOS 6和IOS 7上运行良好。但它在IOS 8上运行的iPad Air和iPad mini 2上运行起来很奇怪。当用户将手柄拉向一个方向时,线的起点移向相反方向。这就像是反向坐标计算 -(void)drawStraightLine { CGContextRef context = UIGraphicsGetCurrentContext(); // set t
-(void)drawStraightLine
{
CGContextRef context = UIGraphicsGetCurrentContext();
// set the line properties
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 2.5);
CGContextSetAlpha(context, 1.0);
// draw the line
CGContextMoveToPoint(context, d.x, d.y);
CGContextAddLineToPoint(context, c.x, c.y);
CGContextStrokePath(context);
}
-(void)showHandles
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(ctx, [UIColor grayColor].CGColor);
CGContextMoveToPoint(ctx, a.x, a.y);
CGContextAddLineToPoint(ctx, b.x, b.y);
CGContextMoveToPoint(ctx, c.x, c.y);
CGContextAddLineToPoint(ctx, d.x, d.y);
CGContextStrokePath(ctx);
CGContextMoveToPoint(ctx, a.x, a.y);
for (double t = 0; t < 1; t += EPSILON) {
CGPoint p = [self bezier:t];
CGContextAddLineToPoint(ctx, p.x, p.y);
}
CGContextSetStrokeColorWithColor(ctx, self.lineColor.CGColor);
CGContextSetLineWidth(ctx, 2.5);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextStrokePath(ctx);
//[self showLines:ctx];
CGContextSetFillColorWithColor(ctx, [UIColor blackColor].CGColor);
CGContextFillEllipseInRect(ctx, CGRectMake(a.x-5, a.y-5, 10, 10));
CGContextFillEllipseInRect(ctx, CGRectMake(b.x-5, b.y-5, 10, 10));
CGContextFillEllipseInRect(ctx, CGRectMake(c.x-5, c.y-5, 10, 10));
CGContextFillEllipseInRect(ctx, CGRectMake(d.x-5, d.y-5, 10, 10));
CGContextSetFillColorWithColor(ctx, [UIColor clearColor].CGColor);
CGContextSelectFont(ctx, "Helvetica", 18.0, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextSetTextMatrix(ctx, CGAffineTransformMakeScale(1.0, -1.0));
NSString *label = [NSString stringWithFormat:@"(%.0f,%.0f)", a.x, a.y];
label = [NSString stringWithFormat:@"(%.0f,%.0f)", c.x, c.y];
CGContextShowTextAtPoint(ctx, fmax(30, fmin(self.bounds.size.width - 80, c.x - 10)), fmax(30, fmin(self.bounds.size.height - 44, c.y + 10)), [label UTF8String], [label length]);
//[NSString drawAtPoint:aPoint withAttributes:dictOfAttributes];
label = [NSString stringWithFormat:@"(%.0f,%.0f)", d.x, d.y];
CGContextShowTextAtPoint(ctx, fmax(30, fmin(self.bounds.size.width - 80, d.x - 10)), fmax(30, fmin(self.bounds.size.height - 44, d.y + 10)), [label UTF8String], [label length]);
label = [NSString stringWithFormat:@"(%.0f,%.0f)", b.x, b.y];
CGContextShowTextAtPoint(ctx, fmax(30, fmin(self.bounds.size.width - 80, b.x - 10)), fmax(30, fmin(self.bounds.size.height - 44, b.y + 10)), [label UTF8String], [label length]);
CGContextShowTextAtPoint(ctx, fmax(30, fmin(self.bounds.size.width - 80, a.x - 10)), fmax(30, fmin(self.bounds.size.height - 44, a.y + 10)), [label UTF8String], [label length]);
}
显示跟踪触摸坐标的代码,以及显示iOS7和iOS8之间坐标差异的代码中的一些nslog是值得的。在iOS8中,屏幕边界更改为面向接口,而不是面向设备。如果你在计算中使用屏幕边界,这可能是你的问题。这是个好主意。谢谢我很快就会试试,我想这就是重点!还在努力修复它。当我在Y轴上移动手指时,点开始沿X轴移动。同样,当我在X轴上移动手指时,点开始沿Y轴移动。