ios - How do I use translationInView: with UIPanGestureRecognizer to have an invisible slider effect? -


as shortcut (by no means necessary) have uipangesturerecognizer on view allow user slide his/her finger , down set value quickly, i'm having trouble implementing fully.

i want have distance panned or down increases or decreases value proportionately.

i tried use translationinview:, seems updating few times unless pan slowly, unless i'm using wrong.

- (ibaction)handlepan:(uipangesturerecognizer *)recognizer {     cgpoint velocity = [recognizer velocityinview:recognizer.view];      nsnumber *wpm = [[nsuserdefaults standarduserdefaults] objectforkey:@"wpm"];      // if user panning upward     if (velocity.y < 0) {         cgpoint translation = [recognizer translationinview:recognizer.view];          if (fmodf(translation.y, 10) == 0) {             wpm = @([wpm intvalue] + 5);             [[nsuserdefaults standarduserdefaults] setobject:wpm forkey:@"wpm"];             nslog(@"%@", wpm);         }     }     // if user panning downward     else if (velocity.y > 0) {         cgpoint translation = [recognizer translationinview:recognizer.view];         if (fmodf(translation.y, 10) == 0) {             wpm = @([wpm intvalue] - 5);             [[nsuserdefaults standarduserdefaults] setobject:wpm forkey:@"wpm"];             nslog(@"%@", wpm);         }     } } 

if drag slowly, variable's value climb relatively fast, if slide finger screen quickly, barely adjusts value @ all. want exact opposite of this; slow movement allows fine control, while fast motion allows quicker change.

how go implementing this? it's not working is.

the trouble algorithm registers change when happens exact multiple of ten. pan faster, each registered translation.y may change >1, not exact multiples register, resulting in fewer increments, not more.

you want register change whenever exceeds ten, reset zero.

- (ibaction)handlepan:(uipangesturerecognizer *)recognizer {     nsnumber *wpm = [[nsuserdefaults standarduserdefaults] objectforkey:@"wpm"];     cgpoint translation = [recognizer translationinview:recognizer.view];     if (translation.y<-10 || translation.y>10) {         int sign = (translation.y>0)?-1:1;             [recognizer settranslation:cgpointmake(0, 0) inview:self.view];             wpm = @([wpm intvalue] + sign*5);             [[nsuserdefaults standarduserdefaults] setobject:wpm forkey:@"wpm"];             nslog(@"%@", wpm);         } } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -