【发布时间】:2010-12-01 01:47:12
【问题描述】:
我试图在 UIView 中的背景图像上绘制一条线,以跟踪用户手指的移动。我可以通过将 UIImage 绘制为背景然后在 drawRect 中绘制线条来完成此操作,但是每次调用 drawRect 时我都必须加载图像,这会使性能变慢。或者,如果我使用 UIImageView 作为我的背景图像(只需将其添加到 IB 中的视图或以编程方式),当它被拖动到图像上时,线条就会消失。有没有办法告诉在 UIImageView 上绘制线条。感谢您的帮助。
这是我使用 UIImage 方法的代码:
- (void)drawRect:(CGRect)rect {
UIImage *imageField = [UIImage imageNamed:@"field.jpg"];
CGRect rectForImage=CGRectMake(0,0,200,200);
[imageField drawInRect:rectForImage];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, x1, y1);
CGContextAddLineToPoint(context, x2, y2);
CGContextStrokePath(context);
}
【问题讨论】:
标签: iphone