我想NSMutableArray
存储触摸时间间隔,但遇到了一个问题:
的NSMutableArray
计数仅为1
. 我能做些什么?
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);
}
}