xcode - iPhone - Wheel tracking finger jumps to same starting position? -


i trying implement selection wheel in iphone application. have got wheel track users finger reason when user touches screen wheel jumps same section of wheel tracks finger each time.

how wheel rotates user dragging point?

-(void) touchesmoved:(nsset *)touches withevent:(uievent *)event { nsset *alltouches = [event alltouches];  int tinput = [alltouches count]-1;  uitouch *touch =[[alltouches allobjects] objectatindex:tinput]; cgpoint location = [touch locationinview:self.view]; float theangle = atan2( location.y-imagex.center.y, location.x-imagex.center.x );  cgaffinetransform cgarotate = cgaffinetransformmakerotation(theangle); imagex.transform = cgarotate; 

}

any suggestion?

right - makes perfect sense - indeed code does.

what need add initial value started drag relative rotation -- or track last rotation.

a elaborate way shown below - should point across.

@interface untitledviewcontroller : uiviewcontroller {         cgpoint firstloc;         uilabel * fred;         double angle; } @property (assign) cgpoint firstloc; @property (retain) uilabel * fred;  @implementation untitledviewcontroller @synthesize fred,firstloc;  - (void)viewdidload {     [super viewdidload];      self.fred = [[uilabel alloc] initwithframe:cgrectmake(100,100,100,100)];     fred.text = @"fred!"; fred.textalignment = uitextalignmentcenter;     [self.view addsubview:fred];      angle = 0; // aint have rotated yet... };  // make sure them drag events. - (bool)isfirstresponder { return yes; }   -(void)handleobject:(nsset *)touches            withevent:(uievent *)event               islast:(bool)lst  {     uitouch *touch =[[[event alltouches] allobjects] lastobject];     cgpoint curloc = [touch locationinview:self.view];      float fromangle = atan2( firstloc.y-fred.center.y,                               firstloc.x-fred.center.x );     float toangle = atan2( curloc.y-fred.center.y,                             curloc.x-fred.center.x );      // angle rotate relative our current angle ,     // angle through our finger moved (to-from)     float newangle = angle + (toangle - fromangle);      cgaffinetransform cgarotate = cgaffinetransformmakerotation(newangle);     fred.transform = cgarotate;      // 'save' current angle when we're done drag.     //     if (lst)         angle = newangle;     }  -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch =[[[event alltouches] allobjects] lastobject];      // capture started - can later work out      // rotation relative point.     //     firstloc = [touch locationinview:self.view]; };   -(void) touchesmoved:(nsset *)touches withevent:(uievent *)event {     [self handleobject:touches withevent:event islast:no]; };  -(void) touchesended:(nsset *)touches withevent:(uievent *)event {     [self handleobject:touches withevent:event islast:yes]; } 

obviously can lot more elegant - , above misses bit of 0 .. 2xpi capping need.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -