iphone - Custom actions for UIGestureRecognizers (with custom parameters) -
short version of problem:
i cannot figure out how make "action" uitapgesturerecognizer take additional parameters, , use them.
here's rundown of problem:
i trying make ipad app records (with nslog) coordinates of uitouch occurs whenever press 1 of app's uibuttons. location of touch needs relative button touched.
what i've done:
i have implemented uitapgesturerecognizer , added each of buttons. problem action use, since needs dynamic each , every button.
i have code:
uitapgesturerecognizer *iconclickrecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(logicon:withtag:)]; [iconclickrecognizer setnumberoftapsrequired:1]; [iconclickrecognizer setnumberoftouchesrequired:1]; [iconclickrecognizer setdelegate:self]; [[self.view viewwithtag:1] addgesturerecognizer:iconclickrecognizer]; [iconclickrecognizer release];
when know works, use for-loop add iconclickrecognizer of buttons tag.
the logicon:(int)withtag method shown here:
-(void)logicon:(uigesturerecognizer *)gesturerecognizer withtag:(int)tag { nslog(@"tag x: %f", [gesturerecognizer locationinview:(uiview*)[self.view viewwithtag:tag]].x); nslog(@"tag y: %f", [gesturerecognizer locationinview:(uiview*)[self.view viewwithtag:tag]].y); }
what isn't working:
when hard-code tag logicon method, records information correctly. however, i not know how make method dynamic, , use "tag" parameter.
any appreciated.
thanks, alex
the docs uigesturerecognizer class specify action must of form:
- (void)handlegesture; - (void)handlegesture:(uigesturerecognizer *)gesturerecognizer;
not form of:
- (void)logicon:(uigesturerecognizer *)gesturerecognizer withtag:(int)tag
so ask gesturerecognizer on whole window, compare buttons, or walk through buttons , ask gesture respect each button.
probably best subclass uibutton , make each button target; know view you're in.
Comments
Post a Comment