【发布时间】:2009-03-25 02:12:47
【问题描述】:
我想让用户在 iPhone 屏幕上画一个签名,所以我添加了 UIView 的一个子类,并在它的“touchesMoved”方法中添加了一些代码。
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
firstTouch = [touch locationInView:self];
CGSize mySize = CGSizeMake(5, 5);
UIGraphicsBeginImageContext(mySize);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
CGContextAddRect(ctx, CGRectMake(0, 0, 5, 5));
CGContextFillPath(ctx);
UIImage *redRect = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *redRectView = [[UIImageView alloc] initWithImage:redRect];
redRectView.center = CGPointMake(firstTouch.x, firstTouch.y);
[self addSubview:redRectView];
}
我用小矩形绘制它,结果是一个点一个点。因为太丑了,我想用线条画出签名。但是如何区分firstTouch和lastTouch呢?如果我只使用'touchesMoved'方法,我只能得到一个接触点。
【问题讨论】:
标签: iphone objective-c opengl quartz-graphics paint