这是相关代码:
@property (nonatomic, strong) NSMutableArray *coordinateInPixels;
...
NSLog(@"First log %@",self.coordinateInPixels);
NSLog(@"self.zoomScale %f",self.zoomScale);
if ([self.coordinateInPixels count]>0) {
NSMutableArray *coordInScala = self.coordinateInPixels;
for (int i=0; i<[coordInScala count]; i++) {
CGPoint puntoRicalcolato = CGPointMake([[coordInScala objectAtIndex:i] CGPointValue].x*self.zoomScale,
[[coordInScala objectAtIndex:i] CGPointValue].y*self.zoomScale);
[coordInScala replaceObjectAtIndex:i withObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
}
[self DrawRoute:coordInScala];
}
NSLog(@"Third log %@",self.coordinateInPixels);
DrawRoute 很简单:
- (void)DrawRoute:(NSMutableArray *)coords
{
self.route = [[ALCRoute alloc] init];
[self.route setCoord:coords];
CGRect rettangolo = CGRectMake([[coords objectAtIndex:0] CGPointValue].x, [[coords lastObject] CGPointValue].y, [[coords lastObject] CGPointValue].x-[[coords objectAtIndex:0] CGPointValue].x, [[coords objectAtIndex:0] CGPointValue].y-[[coords lastObject] CGPointValue].y);
NSLog(@"Second log %@",self.coordinateInPixels);
[self.route setFrame:rettangolo];
[self addSubview:self.route];
}
问题定义:
问题是 self.coordinateInPixels 的元素在第二个和第三个日志中与第一个不同。在drawroute之前没有任何其他操作,但是神奇的元素会在没有(显然显然)任何原因的情况下发生变化......有什么想法吗?
这是输出控制台:
2013-04-11 12:00:05.265 APP[4233:14c03] First log (
"NSPoint: {2442.0994, 2088.6094}",
"NSPoint: {2442.0994, 2088.6094}",
"NSPoint: {1968.8776, 1395.6793}",
"NSPoint: {1965.4939, 1390.1688}",
"NSPoint: {1962.0531, 1384.6427}",
"NSPoint: {2442.0752, 2088.6128}",
"NSPoint: {2442.0752, 2088.6128}",
"NSPoint: {2167.9409, 1604.3606}",
"NSPoint: {2164.2456, 1598.6599}",
"NSPoint: {2160.8596, 1593.2056}",
"NSPoint: {2157.3921, 1587.6027}"
)
2013-04-11 12:00:05.266 APP[4233:14c03] self.zoomScale 0.552063
2013-04-11 12:00:05.266 APP[4233:14c03] Second log (
"NSPoint: {1348.1931, 1153.0443}",
"NSPoint: {1348.1931, 1153.0443}",
"NSPoint: {1086.9448, 770.50317}",
"NSPoint: {1085.0768, 767.461}",
"NSPoint: {1083.1772, 764.41022}",
"NSPoint: {1348.1798, 1153.0461}",
"NSPoint: {1348.1798, 1153.0461}",
"NSPoint: {1196.8403, 885.70837}",
"NSPoint: {1194.8003, 882.56128}",
"NSPoint: {1192.931, 879.55011}",
"NSPoint: {1191.0167, 876.45697}"
)
2013-04-11 12:00:05.267 APP[4233:14c03] Third log (
"NSPoint: {1348.1931, 1153.0443}",
"NSPoint: {1348.1931, 1153.0443}",
"NSPoint: {1086.9448, 770.50317}",
"NSPoint: {1085.0768, 767.461}",
"NSPoint: {1083.1772, 764.41022}",
"NSPoint: {1348.1798, 1153.0461}",
"NSPoint: {1348.1798, 1153.0461}",
"NSPoint: {1196.8403, 885.70837}",
"NSPoint: {1194.8003, 882.56128}",
"NSPoint: {1192.931, 879.55011}",
"NSPoint: {1191.0167, 876.45697}"
)
解决方案!
改变这个:
if ([self.coordinateInPixels count]>0) {
NSMutableArray *coordInScala = self.coordinateInPixels;
for (int i=0; i<[coordInScala count]; i++) {
CGPoint puntoRicalcolato = CGPointMake([[coordInScala objectAtIndex:i] CGPointValue].x*self.zoomScale,
[[coordInScala objectAtIndex:i] CGPointValue].y*self.zoomScale);
[coordInScala replaceObjectAtIndex:i withObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
}
[self DrawRoute:coordInScala];
}
有了这个:
if ([self.coordinateInPixels count]>0) {
NSMutableArray *coordInScala = [[NSMutableArray alloc] init];
for (int i=0; i<[self.coordinateInPixels count]; i++) {
CGPoint puntoRicalcolato = CGPointMake([[self.coordinateInPixels objectAtIndex:i] CGPointValue].x*self.zoomScale,
[[self.coordinateInPixels objectAtIndex:i] CGPointValue].y*self.zoomScale);
[coordInScala addObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
}
[self DrawRoute:coordInScala];
}
一切都开始正常工作......