ios - With UIPanGestureRecognizer, is there a way to only act so often, like after x many pixels were panned? -
right uipangesturerecognizer recognizes every single pan, great , necessary, i'm using sliding gesture increase , decrease variable's value, within method want act every often. if increment 1 every time it's detected value goes far fast.
is there way like, every 10 pixels of panning this, or similar?
you're looking translationinview:
, tells how far pan has progressed , can tested against minimum distance. solution doesn't cover case go , forth in 1 direction in amount equal minimum distance, if that's important scenario it's not hard add.
#define kminimumpandistance 100.0f uipangesturerecognizer *recognizer; cgpoint lastrecognizedinterval; - (void)viewdidload { [super viewdidload]; recognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(didrecognizepan:)]; [self.view addgesturerecognizer:recognizer]; } - (void)didrecognizepan:(uipangesturerecognizer*)sender { cgpoint thisinterval = [recognizer translationinview:self.view]; if (abs(lastrecognizedinterval.x - thisinterval.x) > kminimumpandistance || abs(lastrecognizedinterval.y - thisinterval.y) > kminimumpandistance) { lastrecognizedinterval = thisinterval; // add method call here } }
Comments
Post a Comment