ios - Invoking touchesEnded: when tapped but not swiped -


i'm wanting invoke touchesended: method when user tapped on specific location on screen not when user swipped on screen. how can achieve this?

from debugging, seems touchesended: called when user either tapped or swipped. suppose can add local variable track if user had swipped below think there more robust way of handling this:

bool trackswipe  = no;  // local variable  -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event {      trackswipe = yes;      // }  -(void)touchesended:(nsset *)touches withevent:(uievent *)event{      if (trackswipe == yes)          return;      else      {          cgpoint touchpoint = [[touches anyobject] locationinview:self];          // additional work      } } 

i have looked adding uitapgesturerecognizer invoke tap selector approach doesn't allow me find touchpoint important have.

i appreciate on this. many thanks.

you can try using uitapgesturerecognizer

viewcontroller.h:

#import <uikit/uikit.h>  @interface viewcontroller : uiviewcontroller <uigesturerecognizerdelegate>  @end 

viewcontroller.m:

- (void)viewdidload {     [super viewdidload];      uitapgesturerecognizer *recognizer = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapmethod:)];     recognizer.numberoftapsrequired = 1;     recognizer.numberoftouchesrequired = 1;     recognizer.delegate = self;      [self.view addgesturerecognizer:recognizer]; }  - (void)tapmethod:(uitapgesturerecognizer *)recognizer {     cgpoint touch = [recognizer locationinview:yourviewhere];     nslog(@"x: %f y: %f",touch.x,touch.y); } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -