ios - 怎么画的时候不清空UIView?

标签 ios objective-c drawing cgcontext

我正在 UIView 上画一条线。当我调用 -setNeedsDisplay 时,我的 View 变得清晰并绘制新线。如何继续当前行?以及如何用动画绘制?谢谢。

- (void)drawRect:(CGRect)rect {

    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [_color CGColor]);
    CGContextSetLineWidth(context, 10.0);
    CGContextMoveToPoint(context, _startPointX, 0);
    CGContextAddLineToPoint(context, _endPointX, 0);
    CGContextStrokePath(context);
}

最佳答案

setNeedsDisplay 完全重绘 View 。因此,您需要将所有绘图存储在某处并在每次重绘时应用它。 动画绘图是什么意思?动画绘图就是绘图本身。只需在每次微小更改后重新绘制 View ,看起来就像您自然地绘制一样。

关于ios - 怎么画的时候不清空UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22553662/

相关文章:

有效绘制树木的算法?

ios - 导航栏phonegap插件

ios - 插入 Nib 加载过程

ios - 滚动时如何停止在 UICollectionViewCell 内的 YTPlayerView 中播放视频?

ios - iOS 中的 CALayer 在设备方向更改时自动调整大小

ios - 释放 ViewController 形成 UINavigationController 内的内存

javascript - 什么更快;画一条线或创建一个 div?

Android:对于 Canvas 动画,最好有 1 个大线程,或多个小线程

ios - Google Places API 解析特定位置的详细信息

ios - 多行文本的选定 UITextRange 调整的 CGRect?