i have 2 different uiview on uiviewcontroller.
that uiview left uiview (leftscreenview) , right uiview(rightscreenview).
they differentiate subview leftjoystickview(on leftscreenview) , rightjoystickview(on rightscreenview).
but found problem below:
when touch on leftscreenview , moving, touch other finger on rightscreenview.
now touch event become on leftscreenview. can't differentiate between leftscreenview , rightscreenview event.
i need touch on leftscreenview , moving , touch on rightscreenview moving different event (do moving) @ same time.
how can process multi touch distinguishing different moving event , began event?
#pragma mark ----- touch action ----- -(void) touchesbegan:(nsset *)touches withevent:(uievent *)event { // nslog(@"------touchesbegan-------"); uitouch *touch = [[event alltouches] anyobject]; cgpoint touchviewpoint = [touch locationinview:touch.view]; cgpoint touchleftscreenpoint = [touch.view convertpoint:touchviewpoint toview:self.leftscreenview]; cgpoint touchrightscreenpoint = [touch.view convertpoint:touchviewpoint toview:self.rightscreenview]; nslog(@"touch left:%d",[self.leftscreenview pointinside:touchleftscreenpoint withevent:event]); nslog(@"touch right:%d",[self.rightscreenview pointinside:touchrightscreenpoint withevent:event]); nslog(@"touch.tapcount:%ld", touch.tapcount); if( [self.leftscreenview pointinside:touchleftscreenpoint withevent:event] ) { nslog(@"began click left screen"); self.leftsticklfconstraint.constant = touchleftscreenpoint.x ; self.leftsticktopstickconstraint.constant = touchleftscreenpoint.y ; [self.leftjoystickview touchesbegan:touches withevent:event]; }else if( [self.rightscreenview pointinside:touchrightscreenpoint withevent:event] ) { nslog(@"began click right screen"); self.rightsticklfconstraint.constant = touchrightscreenpoint.x ; self.rightsticktopconstraint.constant = touchrightscreenpoint.y ; [self.rightjoystickview touchesbegan:touches withevent:event]; } nslog(@" "); }
the move event below:
-(void) touchesmoved:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [[event alltouches] anyobject]; cgpoint touchviewpoint = [touch locationinview:touch.view]; nslog(@"moved touch.tapcount:%ld", touch.tapcount); nslog(@"moved touches count:%ld", [touches count]); cgpoint touchleftscreenpoint = [touch.view convertpoint:touchviewpoint toview:self.leftscreenview]; cgpoint touchrightscreenpoint = [touch.view convertpoint:touchviewpoint toview:self.rightscreenview]; if( [self.leftscreenview pointinside:touchleftscreenpoint withevent:event] ) { nslog(@"touchesmoved click left screen"); [self.leftjoystickview touchesmoved:touches withevent:event]; }else if( [self.rightscreenview pointinside:touchrightscreenpoint withevent:event] ) { nslog(@"touchesmoved click right screen"); [self.rightjoystickview touchesmoved:touches withevent:event]; } }
when keep on leftscreenview @ moving, touch rightscreenview.
i touch left:1 touch right:0.
log:
2015-05-08 14:20:30.946 droneg2[3606:942222] touchesmoved click left screen 2015-05-08 14:20:30.947 droneg2[3606:942222] touches count:1 2015-05-08 14:20:30.962 droneg2[3606:942222] moved touch.tapcount:1 2015-05-08 14:20:30.962 droneg2[3606:942222] moved touches count:1 2015-05-08 14:20:30.962 droneg2[3606:942222] touchesmoved click left screen 2015-05-08 14:20:30.963 droneg2[3606:942222] touches count:1 2015-05-08 14:20:30.982 droneg2[3606:942222] moved touch.tapcount:1 2015-05-08 14:20:30.982 droneg2[3606:942222] moved touches count:1 2015-05-08 14:20:30.983 droneg2[3606:942222] touchesmoved click left screen 2015-05-08 14:20:30.983 droneg2[3606:942222] touches count:1 2015-05-08 14:20:30.984 droneg2[3606:942222] touch left:1 2015-05-08 14:20:30.985 droneg2[3606:942222] touch right:0
how can process multi touch on different uiview?
i had add below in viewdidload:
self.leftscreenview.multipletouchenabled = no; self.rightscreenview.multipletouchenabled = no; // self.leftscreenview.exclusivetouch = no; // self.rightscreenview.exclusivetouch = no; self.view.multipletouchenabled = yes;
my storyboard screenshot :
thank much.
add uigesturerecognizer
each of views inside -viewdidload
. uigesturerecognizer
able track state of gesture. example can use following.
//add gesture recognizer each view uipangesturerecognizer *pangesture = [[uipangesturerecognizer alloc] initwithtarget:self action: @selector(handlepan:)]; pangesture.minimumnumberoftouches = 1; [self.myview addgesturerecognizer:pangesture];
now inside of -handlepan
can track state , view contains gesture.
- (void)handlepan:(uipangesturerecognizer *)gesture{ uiview *view = gesture.view; //view contains gesture if(gesture.state == uigesturerecognizerstatebegan){ }else if(gesture.state == uigesturerecognizerstatechanged){ }else if(gesture.state == uigesturerecognizerstateended){ } }
edit:
to distinguish between left , right view can add tag
each view.
leftview.tag = 0; rightview.tag = 1;
then inside of -handlepan:
uiview *view = gesture.view; //view contains gesture if(view.tag == 0) //... if(view.tag == 1) //...
edit2:
you need add gesture left , right view, not view of view controller.
- (void)viewdidload { [super viewdidload]; self.leftscreenview.tag = 0; self.rightscreenview.tag = 1; uipangesturerecognizer *pangesture = [[uipangesturerecognizer alloc] initwithtarget:self action: @selector(handlepan:)]; pangesture.minimumnumberoftouches = 1; [self.leftscreenview addgesturerecognizer:pangesture]; uipangesturerecognizer *pangesture1 = [[uipangesturerecognizer alloc] initwithtarget:self action: @selector(handlepan:)]; pangesture1.minimumnumberoftouches = 1; [self.rightscreenview addgesturerecognizer:pangesture1]; }
Comments
Post a Comment