This is my testing code
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];
NSLog(@"start (%f, %f)", gestureStartPoint.x, gestureStartPoint.y);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
NSLog(@"move (%f, %f)", currentPosition.x, currentPosition.y);
}
From my understanding [touches anyObject] will return a开发者_如何学运维ny object (any finger that touching the screen), so I begin my test in simulator by option+click the screen repeatedly the result is what I expected the x, y point randomly change from one to another. My question is on touchesMoved after I touch with two finger (option+click) I begin to drag and expected that x, y will change randomly like touchesBegan, but the result amazed me, the x, y will be the same (same finger co-or) as one I got from touchesBegan.
So this behavior have explanation somewhere ?
From: NSSet Class Reference
- (id)anyObject
Return Value
One of the objects in the set, or nil if the set contains no objects. The object returned is chosen at the set’s convenience—the selection is not guaranteed to be random.
I assume that internally they are kept in order (or generated based on coordinates) and added to the set in order, and it is just convenient for the set to give them to you in that order
精彩评论