objective-c - 手指画的效率问题

标签 objective-c ios performance drawing fingerprint

我想开发一个应用程序来绘制触摸 iPhone 屏幕并搜索如何做我在 Erica Sadun iPhone 开发人员手册的第八章中找到了一个示例配方 (09-Paint) 3.0 Code Samples .在示例中,正如您在这行下方看到的那样,屏幕上的触摸被存储到 NSMutableArray 中,稍后使用 UIView 方法 drawRect.

使用此解决方案时,当 points 数组保留大量点时,我会遇到问题。我怎么解决这个问题?如何调用 drawRect 方法而不清除 UIView 并仅添加最后一行(在已绘制的线和 points 的最后一个点之间) > 阵列)?

// Start new array
- (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event
{
    self.points = [NSMutableArray array];
    CGPoint pt = [[touches anyObject] locationInView:self];
    [self.points addObject:[NSValue valueWithCGPoint:pt]];
}

// Add each point to array
- (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event
{
    CGPoint pt = [[touches anyObject] locationInView:self];
    [self.points addObject:[NSValue valueWithCGPoint:pt]];
    [self setNeedsDisplay];
}

// Draw all points
- (void) drawRect: (CGRect) rect
{
    if (!self.points) return;
    if (self.points.count < 2) return;

    CGContextRef context = UIGraphicsGetCurrentContext();
    [current set];
    CGContextSetLineWidth(context, 4.0f);

    for (int i = 0; i < (self.points.count - 1); i++)
    {
        CGPoint pt1 = POINT(i);
        CGPoint pt2 = POINT(i+1);
        CGContextMoveToPoint(context, pt1.x, pt1.y);
        CGContextAddLineToPoint(context, pt2.x, pt2.y);
        CGContextStrokePath(context);
    }
}

感谢阅读。

最佳答案

现在一切正常。 SkylarEC 有很棒的教程 here ,他解释了如何解决这个问题。感谢阅读。

关于objective-c - 手指画的效率问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5111962/

相关文章:

.net - 克隆 HashSet<T> 的有效方法?

javascript - 建立 WebSockets 连接时 CPU 消耗 100%

ios - 如何使 AVPlayer 随父 View 调整大小?

ios - double 丢失

ios - “Video is currently unavailable”-iOS应用程序的Youtube Javascript/iFrame API(嵌入UIWebview)

ios - 使用正则表达式验证字符串

ios - xcode 中的 iphonesimulator(未找到 SDK)错误

performance - 使用 Group By 和 Like 的 Impala 查询性能低下

c++ - 如何在我的 iPhone 应用程序中使用 C++ STL 容器?

objective-c - 将点击聚焦功能添加到 ZBarReaderViewController