Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

畫線段時,第一筆數值為空,無法執行。 #4

Open
gixiphy opened this issue Nov 28, 2018 · 0 comments
Open

畫線段時,第一筆數值為空,無法執行。 #4

gixiphy opened this issue Nov 28, 2018 · 0 comments

Comments

@gixiphy
Copy link

gixiphy commented Nov 28, 2018

你好,因為項目需求,發現线段/折线有兩個問題:
1.畫線段時,第一筆數值為空,無法執行。
2.在前後無數值,無發顯示當前一點。

以下是我的處理方式:

  • (UIBezierPath *)AxcDrawLineArray:(NSArray <NSValue *> *)lineArray
    clockwise:(BOOL)clockwise{
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    if (!lineArray.count) return bezierPath;
    __block BOOL isMovePoint = YES;
    __block CGPoint point = CGPointZero;//紀錄當前點
    [lineArray enumerateObjectsUsingBlock:^(NSValue * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    if ([obj isKindOfClass:[NSValue class]]) {
    if (isMovePoint) {
    [bezierPath moveToPoint: [obj CGPointValue]];
    point = [obj CGPointValue];
    isMovePoint = NO; // 置空判断
    }else{
    [bezierPath addLineToPoint: [obj CGPointValue]];
    point = CGPointZero;
    }
    }else{ // 记录下一个点需要移动,在無上下點時,畫出自己
    if (point.x > 0 && point.y > 0) {
    [bezierPath addLineToPoint: CGPointMake(point.x-0.5, point.y-0.5)];
    point = CGPointZero;
    }
    isMovePoint = YES;
    }
    }];
    if (!clockwise) bezierPath = [bezierPath bezierPathByReversingPath];// 逆时针绘制
    return bezierPath;
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant