【发布时间】:2017-12-06 20:05:44
【问题描述】:
我有一个名为 Slate 的平板电脑,我可以从中处理 x,y 点。我可以将这些 x,y 点传递给我的“drawShape”函数,相当于 touchesMoved 函数。我有一个为此目的设计的自定义 UIView 类,具有 4 个主要功能。前三个是touchesbegan/moved/ended,还有一个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
这是屏幕截图。
我试着写“好吗?”只是为了说明问题。
【问题讨论】:
-
您需要包含足够多的代码,以便其他人可以看到您在做什么,以帮助找出您做错了什么。请看How do I ask a good question?
-
不确定您还需要哪些其他信息。这些是程序运行的 4 个主要功能。
-
这里的一些乐于助人的人可能想要运行您的代码来帮助您调试它...您发布的内容无法运行。见:How to create a Minimal, Complete, and Verifiable example
标签: ios objective-c uiview