android - iOS make gestureRecognizer listen outside of view -


hey using code imitate knob view in app:

- (void) setupgesturerecognizer {     cgpoint midpoint = cgpointmake(image.frame.origin.x + image.frame.size.width / 2,                                    image.frame.origin.y + image.frame.size.height / 2);     cgfloat outradius = image.frame.size.width / 2;     gesturerecognizer = [[onefingerrotationgesturerecognizer alloc] initwithmidpoint: midpoint                                                                          innerradius: outradius / 10                                                                           outerradius: outradius *2                                                                               target: self];     [self.view addgesturerecognizer: gesturerecognizer]; } 

like this, gesturerecognizer handles events happen on or very close button. want following:

  • gesturerecognizer gets triggered when user touches inside image
  • if finger leaves image, gesturerecognizer should continue
    listening (and calculating angle)

on android doing following:

public boolean onscroll(motionevent e1, motionevent e2, float distancex, float distancey) {         float x = e2.getx() / ((float) getwidth());         float y = e2.gety() / ((float) getheight());         float rotdegrees = cartesiantopolar(1 - x, 1 - y);          [...doing maths stuff here] 

i got rotating stuff working how make gesturerecognizer work can handle events in android? if lost internet connection , had no choice code on own take 2 different gesturerecognizers, on handling "init" press , 1 "following" finger everywhere, setting correspondent knob according key value being set in first gesturerecognizer. looks massive pile of bad code me i'd appreciate advice on one.

cheers, alex

you should able use delegate method, gesturerecognizer:shouldreceivetouch: examine location of touch, , return yes if touch point within image view's bounds (using cgrectcontainspoint). if gesture recognizer added image view's superview, should continue "listening" want.

-(bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldreceivetouch:(uitouch *)touch {     cgpoint touchpoint = [touch locationinview:self.view];     return cgrectcontainspoint(self.imageview.frame, touchpoint); } 

also sure set controller delegate of gesture recognizer.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -