English 中文(简体)
形形形形形色时断线。
原标题:Line is erased when drawing shapes
  • 时间:2009-11-04 10:57:25
  •  标签:

我试图通过触动屏幕提出绘画申请。

我可以从一个点到另一个点,但从每个新渠道消失。

我的守则是:

CGPoint location;
CGContextRef context;
CGPoint drawAtPoint;
CGPoint lastPoint;
-(void)awakeFromNib{
    //[self addSubview:noteView];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    location = [touch locationInView:touch.view];
    [self setNeedsDisplayInRect:CGRectMake(0, 0, 320, 480)];
}

- (void)drawRect:(CGRect)rect {
    context = UIGraphicsGetCurrentContext();
    [[UIColor blueColor] set];
    CGContextSetLineWidth(context,10);
    drawAtPoint.x =location.x;
    drawAtPoint.y =location.y;
    CGContextAddEllipseInRect(context,CGRectMake(drawAtPoint.x, drawAtPoint.y, 2, 2));
    CGContextAddLineToPoint(context,lastPoint.x, lastPoint.y);
    CGContextStrokePath(context);

    lastPoint.x =location.x;
    lastPoint.y =location.y;
}

赞赏你的帮助

Nir.

最佳回答

如你所发现的,DrawRect是你显示观点内容的地方。 你们只能看一看你在这里的教训。

这比类似情况低得多。 闪电,如果你可以添加一只含有一线一线的电影片,而一段时间后又加上另一部电影片,其中包含一条线,现在你看到两条线!

你们需要做一些工作,并像现在这样做。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [[event allTouches] anyObject]; 
    location = [touch locationInView:touch.view]; 

    [self addNewLineFrom:lastPoint to:location];

    lastPoint = location;

    [self setNeedsDisplayInRect:CGRectMake(0, 0, 320, 480)]; 
}

- (void)drawRect:(CGRect)rect {

    context = UIGraphicsGetCurrentContext();

    for( Line *eachLine in lineArray )
        [eachLine drawInContext:context];

}

我认为,你能够看到如何把这一点充实到你们需要的东西。

解决这一问题的另一个途径是使用药房。 采用这一方法,你在内部——(避免)完全抽取——添加和删除了几层,从内部抽取你喜欢的东西,并且将视必要处理堆肥和抽取。 或许,你们所期待的东西更多。

问题回答

每次打电话到<代码>drawRect时,你先用一张空白单。 如果你不跟踪你以前所提取的一切情况,以便再次加以利用,那么,你最终只能找你最近的inger子,而不是老的inger子。 您必须随时了解你所有的 f,以便每次打上<代码>drawRect。

你们不去重划每一条线,就能够树立形象,然后在<条码>drawRect:方法上展示形象。 图像将累积给你。 当然,这种方法使得难以执行。

http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgramingGuide/GraphicsandDrawing/GraphicsandDrawing.html#/apple_ref/doc/uid/TP40007072-CH10-SW14” rel=“nofollow noreferer”i 电话应用方案规划指南

Use the UIGraphicsBeginImageContext function to create a new image-based graphics context. After creating this context, you can draw your image contents into it and then use the UIGraphicsGetImageFromCurrentImageContext function to generate an image based on what you drew. (If desired, you can even continue drawing and generate additional images.) When you are done creating images, use the UIGraphicsEndImageContext function to close the graphic context. If you prefer using Core Graphics, you can use the CGBitmapContextCreate function to create a bitmap graphics context and draw your image contents into it. When you finish drawing, use the CGBitmapContextCreateImage function to create a CGImageRef from the bitmap context. You can draw the Core Graphics image directly or use this it to initialize a UIImage object.





相关问题
热门标签