English 中文(简体)
提供文稿免费的最佳途径
原标题:what is the best way to provide free draw hand writing in ios [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
how to create an application which allows user to free hand drawing?

I am trying to implement free hand writing on a view. I used some of the existing code, which is working well when user is writing very slow, where as if the user writes very fast it s not recognizing all the points(what ever the points are touched by the user). my sample code is here

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        mouseSwiped = YES;
    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self];
    currentPoint.y -= 20;


    UIGraphicsBeginImageContext(self.bounds.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    if (mode == DrawingModePen) {
        NSLog(@"drawing");
        CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [_drawingPenColor CGColor]);
    }
    else {
        CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);

        CGContextBeginPath(UIGraphicsGetCurrentContext());


        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 20, 20));
        CGContextStrokePath(UIGraphicsGetCurrentContext());

        NSLog(@"clearing");
            }
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    mouseMoved++;

    if (mouseMoved == 10) {
        mouseMoved = 0;
    }
}

是否有其他办法执行? 我看到了GLPaint由pple提供。 在我的记忆中发出记忆警告,这也没有什么用处。

问题回答

Try out the Rainbow developers tutorial GLPaint 。 它可以帮助开端人开发油漆应用。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签