Super_DL_csdn 2016-12-22 07:39 采纳率: 0%
浏览 2470

iOS CAShapeLayer和UIBezierPath无限绘制图线如何不卡

现在公司有一个要求:连接蓝牙BLE4.0之后,获取传递过来的数据,然后以点的形式连接成线。
我采用的是CAShapeLayer和UIBezierPath绘制曲线,当一开始点比较少的时候,可以非常流畅的把线画出来
但是当点的数目达到3000左右,就会开始卡顿。
因为我们的数据是每秒25个数据,在scrollView上显示的时候回非常卡顿,请问有什么好办法来解决这个问题呢????

以下是绘制的代码:

UIBezierPath *path = [[UIBezierPath alloc] init];
path.usesEvenOddFillRule = YES;
NSString * tt=nil;
float height=self.topScrollView.frame.size.height;

if (objc.BLE_View.minusRangeValue==0) {
     tt=[NSString stringWithFormat:@"{%.2f,%.2f}",timer_number*1.2,objc.BLE_View.positive_k*height*(1-[string floatValue]/[objc.BLE_View.positiveRangeValue floatValue])];
}
else
{
    if (isPositive) {
        tt=[NSString stringWithFormat:@"{%.2f,%.2f}",timer_number*1.2,objc.BLE_View.positive_k*height*(1-[string floatValue]/[objc.BLE_View.positiveRangeValue floatValue])];


    }
    else
    {
        tt=[NSString stringWithFormat:@"{%.2f,%.2f}",timer_number*1.2,objc.BLE_View.minus_k*height*(1+[string floatValue]/[objc.BLE_View.minusRangeValue floatValue])];
    }
}



if (!pointLast.x) {
    pointLast=CGPointFromString(tt);
    [path moveToPoint:pointLast];
    [path addLineToPoint:pointLast];
}
else
{
    [path moveToPoint:pointLast];

    [path addLineToPoint:pointLast];

    [path addLineToPoint:CGPointFromString(tt)];

}


//create shape layer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];

shapeLayer.drawsAsynchronously=YES;
shapeLayer.strokeColor = [UIColor greenColor].CGColor;
shapeLayer.fillColor = [UIColor whiteColor].CGColor;
shapeLayer.lineWidth = 3;
shapeLayer.lineJoin = kCALineJoinRound;//终点处理
shapeLayer.lineCap = kCALineCapRound;//线条拐角
shapeLayer.path = path.CGPath;


//add it to our view


[shapeLayerArr addObject:shapeLayer];


dispatch_sync(dispatch_get_main_queue(), ^{

    [_topScrollView.layer addSublayer:shapeLayer];


    // 设置layer的animation
    _topScrollView.layer.shouldRasterize = YES;

    NSLog(@"------》%f,-------》%f",pointLast.x-10,pointLast.y-10);

    [_topScrollView setNeedsDisplayInRect:CGRectMake(pointLast.x-10, pointLast.y-10, 40, 40)];
    [_topScrollView.layer setNeedsDisplayInRect:CGRectMake(pointLast.x-10, pointLast.y-10, 40, 40)];

    if (pointLast.x>_topScrollView.contentSize.width) {


        _topScrollView.contentSize=CGSizeMake(_topScrollView.contentSize.width+_topScrollView.frame.size.width, 0);
        _topScrollView.contentOffset=CGPointMake(pointLast.x, 0);

    }

    pointLast=CGPointFromString(tt);
});
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2016-12-31 02:53
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧