我正在開發一個應用程序,用戶可以在其中繪製線條。同一個應用程序的桌面版本可以在負座標上繪製線條,我也希望在iOS應用程序中具有相同的功能。iOS - 在負座標上繪製二維線條
我到目前爲止所嘗試的: - 我有一個UIViewController
其中我已經覆蓋- (void)drawRect:(CGRect)rect
並畫出了線。這裏是我使用的代碼: -
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
CGPoint startPoint = CGPointMake(self.startHandle.frame.origin.x + self.startHandle.frame.size.width/2, self.startHandle.frame.origin.y + self.startHandle.frame.size.height/2);
CGPoint endPoint = CGPointMake(self.endHandle.frame.origin.x + self.endHandle.frame.size.width/2, self.endHandle.frame.origin.y + self.endHandle.frame.size.height/2);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, startPoint.x, startPoint.y); //start at this point
CGContextAddLineToPoint(context, endPoint.x, endPoint.y); //draw to this point
它工作得很好,直到我有startPoint.x
爲負值。用負值,我沒有看到0,0座標後面的那一行。任何幫助或信息表示讚賞。
你的意思是改變self.bounds.origin.x爲負值? –
@AnkurArora我的意思是帆布很小,你可以在外面畫一個較大的畫布,其起源是負面的。 – Lumialxk
我無法理解你的意思。如果我增加畫布大小,這將有助於在負座標上繪製線條?因爲用畫布尺寸點(0,0)也會改變。你可以分享一個示例代碼來解釋你想要解釋的內容嗎? –