ios - How can a child ignore a UIGesture in certain circumstances and let the superview handle it? -


i'm implementing similar ios's memory manager. uicollectionview uicollectionviewcell children. if swipe horizontally on cell, parent pans left. however, if swipe vertically, cells move finger.

enter image description here

in uicollectionviewcell subclass, have:

- (id)initwithframe:(cgrect)frame {     if (self = [super initwithframe:frame]) {                 uipangesturerecognizer* pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(didpan:)];         pan.maximumnumberoftouches = 1;         pan.minimumnumberoftouches = 1;         [self addgesturerecognizer:pan];     }     return self; } 

unfortunately, child cells handling pan gestures. parent never gets handle them.

- (void)didpan:(uipangesturerecognizer *)gesture {     cgpoint velocity = [gesture velocityinview:self.superview];     if (abs(velocity.y) > abs(velocity.x)) {         // move cell finger     } else {         // let parent uicollectionview pan horizontally     } } 

i know how move cell finger, don't know how other case: making child cell ignore pan gesture , letting parent handle it.

you need have cell's pan gesture recognizer recognize simultaneously collection view's pan gesture recognizer.

there few ways this, 1 way making cell delegate of pan gesture recognizer , implementing method:

- (bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldrecognizesimultaneouslywithgesturerecognizer:(uigesturerecognizer *)othergesturerecognizer {     // either return yes allow cell's gesture recognizer     // work simultaneously other recognizers:     return yes;      // or can decide whether cell's pan gesture recognizer should     // recognize simultaneously othergesturerecognizer. example,     // reference collection view's pangesturerecognizer     // , return yes if othergesturerecognizer equal recognizer:     return othergesturerecognizer == <your collection view's gesture recognizer>; } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -