ios - UIPanGestureRecognizer stops working when when panned up, not when panned down -
i'm creating screen dimmer here. i've put black view on screen , using uipangesturerecognizer adjust opacity based on whether user scrolls or down. here's code:
- (ibaction)dimscreen:(uipangesturerecognizer *)sender { //get translation cgpoint translation = [sender translationinview:self.view]; cgfloat distance = translation.y; //add fraction of translation alpha cgfloat newalpha = self.blackscreen.alpha + distance/self.view.frame.size.height; //check if alpha more 1 or less 0 if (newalpha>1) { newalpha = 1; }else if (newalpha<0.0){ newalpha = 0.0; } self.blackscreen.alpha = newalpha; //reset translation incremental change [sender settranslation:cgpointzero inview:self.view]; }
if pan down, opacity goes 1.0, , can still adjust it. if pan till opacity 0, can no longer pan @ all. dimscreen: selector stops getting called. can describe causing issue?
views alpha values of 0 no longer receive touches. in fact, seems below 0.011 alpha view stops receiving touches. so, code can made work changing values in else-if statement:
if (newalpha>1) { newalpha = 1; }else if (newalpha <= 0.011){ newalpha = 0.011; }
i've seen other people mention value of 0.02 instead of 0.011 found empirically. don't know how "safe" assume either of these numbers fixed , continue work in future, seems work now.
Comments
Post a Comment