ios - Sparrow: How to have different events for touch and drag -


basically want touch image rotate centre 90 degrees. drag image move (without rotating).

- (void) onimagetouched:(sptouchevent *)event {     spimage *img = (spimage *)event.target;     sptouch *drag = [[event toucheswithtarget:self andphase:sptouchphasemoved] anyobject];     sptouch *touch = [[event toucheswithtarget:self andphase:sptouchphasebegan] anyobject];     float offsetx, offsety;     if(touch){         sppoint *initial = [touch locationinspace:self];         offsetx = initial.x - img.x;         offsety = initial.y - img.y;     }     if (drag) {         sppoint *dragposition = [drag locationinspace:self];         nslog(@"touched (%f %f)",dragposition.x, dragposition.y);         //img.x = dragposition.x - offsetx;         //img.y = dragposition.y - offsety;      }     else{         img.pivotx = img.width / 2.0f;         img.pivoty = img.height / 2.0f;         nslog(@"rotated aboout(%f %f)",img.pivotx,img.pivoty);         //img.rotation = sp_d2r(90);     }  } 

above code.

when drag it, move image's position quite far pointers. also, @ start , end of dragging, image rotates.

when tap it, disappears. (maybe move or rotate somewhere outside screen)

any suggestions?

ok woould this:

- (void) onimagetouched:(sptouchevent *)event {     spimage *img = (spimage *)event.target;     sptouch *drag = [[event toucheswithtarget:self andphase:sptouchphasemoved] anyobject];     sptouch *touch = [[event toucheswithtarget:self andphase:sptouchphasebegan] anyobject];     sptouch *endtouch = [[event toucheswithtarget:self andphase:sptouchphaseended] anyobject];     float offsetx, offsety;         static bool dragging = no;     if(touch){         dragging = no;     } else if (drag) {         dragging = yes;         sppoint *dragposition = [drag locationinspace:self];         nslog(@"touched (%f %f)",dragposition.x, dragposition.y);         img.x = dragposition.x;         img.y = dragposition.y;     }     else if (endtouch) {         if (!dragging) {             img.pivotx = img.width / 2.0f;             img.pivoty = img.height / 2.0f;             nslog(@"rotated aboout(%f %f)",img.pivotx,img.pivoty);             img.rotation = sp_d2r(90);         }     }  } 

this variant should solve problem of offset while dragging , fact when drag rotates anyway.

note static variable in method (dragging) better if put private variable in implementation (i saved time doing way ;) ).

i haven't test code idea should clear (i hope).

regards


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -