簡體   English   中英

畫線目標c

[英]Draw a line objective c

我是目標C的初學者,我試圖制作一個具有Paint風格的程序,我正在用平移手勢繪制一條線。 我可以做出手勢,但是問題是,每次重新加載之前刪除鼠標的位置時,我都無法在鼠標經過的位置后面拖動。 救命! 非常感謝! 這是該部分中的代碼:

-(void)pan: (UIPanGestureRecognizer*)panGesture
{
    if(panGesture.state == UIGestureRecognizerStateChanged) {    
        _panLocation = [panGesture locationInView:self];
    }
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawLine:context];
}

-(void)drawLine:(CGContextRef)context {    
    if (self.tag == 0) {
        [[UIColor blackColor] setFill];
        UIGraphicsPushContext(context);
        CGContextBeginPath(context);
        CGContextAddArc(context, _panLocation.x, _panLocation.y, 4, 0, 2*M_PI, YES);
        CGContextSetAlpha(context, 1);
        CGContextFillPath(context);
    }
}

我想這會有所幫助

使用UIPanGestureRecognizer進行繪制時,請參考帶有手勢鏈接的繪制線

否則,您可以使用該鏈接后面的觸摸委托方法來執行此操作

觸摸畫線

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM