Is there any way to determine the velocity of a touch motion
I开发者_如何学Go am making a drawing app and I want to increment my brush size depending on the touches velocity.
How would I accomplish this?
Yes. See the methods on UIView
named touches*
, specifically:
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
It gets called when a move ("slide"?) is detected, and doesn't suffer from being "fooled" by multiple quick touches. You can get the coordinate of the current finger position in the view and the time the event ocurred:
UITouch *touch = [touches anyObject];
CGPoint inFrameCoordinate = [touch locationInView:self];
NSTimeInterval timestamp = [touch timestamp]
Get the distance and time between two coordinates to calculate the velocity.
Well, UITouch has properties for location and timestamp; using these properties, you can calculate the "velocity" of the touch between two touch events.
This will only work for single touches, of course, and you may have to smooth the results. Also, the user might be able to "fool" you by quickly tapping with two fingers alternatingly ;-)
精彩评论