我要让NSMutableArray
存储触摸时间上的差距,而是跨越一个问题来了:
的NSMutableArray
的计数只1
。 我能做什么?一旦你触摸屏幕的NSMutableArray对象值相同的值
NSInteger count = 0;
float firstTempTime = 0;
float nTempTime = 0;
float nTouchTimegap = 0;
#pragma mark –
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
messageLabel.text = @"Touches Began";
[self updateLabelsFromTouches:touches];
NSArray *array = [touches allObjects];
for (UITouch *touch in array){
count = count +1;
NSLog(@"began touch count: %d", count);
nTempTime = [touch timestamp];
NSLog(@"n TempTime stamp : %lf", nTempTime);
if (count == 1) {
firstTempTime = [touch timestamp];
}
else {
nTouchTimegap = nTempTime - firstTempTime;
firstTempTime = nTempTime;
}
NSLog(@"nTouchTimegap : %lf", nTouchTimegap);
nTouchTimegapArray = [NSMutableArray arrayWithCapacity:count];
[nTouchTimegapArray addObject:[NSNumber numberWithFloat: nTouchTimegap]];
for(id obj in nTouchTimegapArray){
NSLog(@"nTouchTimegapArray : %i", [nTouchTimegapArray count]);
NSLog(@"nTouchTimegapArray : %@", obj);
}
}
插入更多元素。 –
而且你也可以在循环的外部创建数组,所以你不要在每次迭代中都替换旧数组。 (提示:Objective-C是*程序*语言。) –