概述
我有绘画APP。它注册鼠标事件并将其发送到 NSMutableArray。数组中的后续值被传输到 GLfloat 并像顶点数组一样绘制。因此,所有画笔笔触都会在每次鼠标事件时重绘。
我想做的事?
我想实现撤消重做功能和诸如笔触多样性(柔软度等)之类的东西,所以我需要以某种方式做到每个顶点(鼠标事件位置)都可以有一些额外的设置。我想问这是否可能。
解释
如果用户以100% 的柔软度绘制10 个点(在一次鼠标拖动中),然后将柔软度更改为0%并进行绘制,则必须将前10 个点的笔刷纹理设置为img1,然后将第二个笔触笔刷的纹理设置为img2。
如果有可能对数组进行索引(例如像这样的东西NSMutableArray *array[i++] = [[NSMutableArray alloc] init]
),我认为可以做一些类似于我想要的很容易的事情。但有可能吗?或者你可以建议任何其他解决方案?
PSNSMutableArray *array[i++] = [[NSMutableArray alloc] init]
没有显示任何错误,但也不起作用。
尝试使用NSMutableDictionary
在 mousedown 和 mousedraged 时:
locll = [self convertPoint: [event locationInWindow] fromView:nil];
NSValue *locationValuell = [NSValue valueWithPoint:locll];
[vertices addObject:locationValuell];
在 mouseUp
NSString *index = [NSString stringWithFormat:@"%d", aIndex++];
[aDict setObject:vertices forKey:index];
NSArray *allKeys = [aDict allKeys];
NSLog(@"dict count: %ld", [allKeys count]);
NSString *index1 = [NSString stringWithFormat:@"%d", aIndex];
NSMutableArray *a = [aDict objectForKey:index1];
NSLog(@"a count:%li", [a count]);
在 initWithCoder
int aIndex = 0;
dict count 返回有多少对象存储在字典中。它有效。但后来当我尝试从字典中取回数组时,我检查了数组中有多少对象,它返回 0。