Ios 试图在视图上绘制右上角的对角线

Ios 试图在视图上绘制右上角的对角线,ios,objective-c,uiview,Ios,Objective C,Uiview,我有一个叫做Slate的平板电脑,可以处理x,y点。我可以将这些x、y点传递给我的“drawShape”函数,它相当于TouchsMoved函数。我有一个定制的UIView类,它具有4个主要功能。前三个是触摸开始/移动/结束,有一个drawRect 以下是UIView子类的源代码 // // DrawingLayerView.m // // // Created by Monica Kachlon on 12/3/17. // #import "DrawingLayerView.h" #i

我有一个叫做Slate的平板电脑,可以处理x,y点。我可以将这些x、y点传递给我的“drawShape”函数,它相当于TouchsMoved函数。我有一个定制的UIView类,它具有4个主要功能。前三个是触摸开始/移动/结束,有一个drawRect

以下是UIView子类的源代码

//
//  DrawingLayerView.m
//
//
//  Created by Monica Kachlon on 12/3/17.
//

#import "DrawingLayerView.h"
#include "UIBezierPath+Interpolation.h"


@interface StrokeA : NSObject

@property (assign, nonatomic) CGPoint startPoint;

- (id)initWithStartPoint:(CGPoint)point;


@property (strong, nonatomic) NSMutableArray * points;

@end

@implementation StrokeA



- (id)initWithStartPoint:(CGPoint)point {
    self = [super init];
    self.startPoint = point;
    self.points = [NSMutableArray array];

    return self;
}


@end



@implementation DrawingLayerView

NSMutableArray * strokes;
NSMutableArray * points;


StrokeA * currentStroke;
UIBezierPath * currentPath;
UIBezierPath *path;
UIBezierPath *pathTwo;

UIBezierPath *Newpath;
CAShapeLayer * currentLayer;


- (void) noodlez
{
path = [UIBezierPath bezierPath];

   currentPath = [UIBezierPath bezierPath];

    pathTwo = [UIBezierPath bezierPath];

    Newpath = [UIBezierPath bezierPath];
     strokes = [NSMutableArray array];
     points = [NSMutableArray array];

}
- (void)startTouch: (CGPoint)point
{

    currentStroke = [[StrokeA alloc] initWithStartPoint:point];
    [strokes addObject:currentStroke];
}

- (UIBezierPath *)createPath {
    UIBezierPath * bezierPath = [UIBezierPath bezierPath];
    for (StrokeA * stroke in strokes) {
        [bezierPath moveToPoint:stroke.startPoint];
        for (NSValue * value in stroke.points) {
            [bezierPath addLineToPoint:[value CGPointValue]];
        }
    }
    return bezierPath;
}


- (void)endTouch: (CGPoint)point
{

    [points removeAllObjects];
    [self setNeedsDisplay];
}
- (void)drawShape: (CGPoint)point
{
    if (!currentStroke) {
        [self startTouch:point];
    }
    [currentStroke.points addObject:[NSValue valueWithCGPoint:point]];
    pathTwo = [self createPath];

    [self setNeedsDisplay];

}

- (void)drawRect:(CGRect)rect {
    [[UIColor blackColor] setStroke];
    [pathTwo stroke];
}


@end
这是截图


我试着写“Ok?”只是为了说明这个问题。

尽管代码缺少一些细节,而且问题的措辞也很糟糕,但屏幕截图清楚地显示了路径的初始点在每种情况下都是(0,0)。将路径中的点转储到控制台,您将看到它。找出那些(0,0)是如何进入的,你就会解决问题。

你需要包含足够的代码,以便其他人可以看到你在做什么,从而帮助找出你做错了什么。请参阅不确定您还需要哪些其他信息。以下是该程序运行的4个主要函数。这里的一些有帮助的人可能希望运行您的代码来帮助您调试它。。。您发布的内容无法运行。见: