Recently I\'m making an app that can drag multiple objects at the same time. I had tried to use UIPanGestureRecognizer to get the coordinates of finger touches,
I've struggled with the same problem for quite a long time and finally solved it. The following is the code in my DrawView.m, which is a subclass of UIView that is able to support drawings using drawRect:.
#import "DrawView.h"
#define MAX_TOUCHES 4
@interface DrawView() {
bool touchInRect[MAX_TOUCHES];
CGRect rects[MAX_TOUCHES];
UITouch *savedTouches[MAX_TOUCHES];
}
@end
@implementation DrawView
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
self.multipleTouchEnabled = YES;
for (int i=0; i
I set the MAX_TOUCHES as 4, so there will be four objects on the screen. The basic concept of this is to store each UITouch ID in the savedTouches array when touchesBegan:: is called, and later compare each ID with the touches on screen when touchesMoved:: called.
Just paste the code into your .m file and it'll work. The sample result is shown here:
Hope this helps :)