ios - Movement of object only when one half of the screen is touched -


in current objective c project coding mechanic when drag hand on 1 half of screen object moves in direct correlation , when drag on other half of screen, other object moves in direct correlation first not. when test project first object moves on half screen, second object not when other half of screen touched

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [[event alltouches] anyobject];     cgpoint location = [touch locationinview:touch.view];      if (location.x <= 259 )          [person setcenter:cgpointmake(location.x, person.center.y)];      if (location.y >289)          [person1 setcenter:cgpointmake(location.x, person1.center.y)]; }  -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event{     uitouch *touch = [[event alltouches] anyobject];     cgpoint location = [touch locationinview:touch.view];      if (location.x <= 259 )          [person setcenter:cgpointmake(location.x, person.center.y)];      if (location.y >289)          [person1 setcenter:cgpointmake(location.x, person1.center.y)]; } 

your objects should moving fine. however, if you're trying split screen in half (as said in question) if statements in touch delegate methods rather odd. here image of "person" object moved depending on touch screen (assuming 4" screen in portrait)

enter image description here

as can see, there section of screen not move either object, , (rather large) section move both of objects. there small area move person1 itself.

if you're wanting assign half of screen each object, suggest doing split top , bottom half of screen:

if(location.y <= self.view.frame.size.height / 2) {     // move person } else {     // move person1 } 

you modify split left/right halves of screen.


if you're still having issues moving both objects, make sure they're hooked view if they're iboutlets


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -