ios - hitTest to dismiss keyboard causing weird behaviour -
i've googled on how dismiss keyboard when touching blank area in uitableview in ios, , there're several ways solve this. using delegate, uitapgesturerecognizer, - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event
, - (uiview *)hittest:(cgpoint)point withevent:(uievent *)event
.
i decide take hittest subclassing corresponding uiview class , override method this:
- (uiview *)hittest:(cgpoint)point withevent:(uievent *)event { uiview *result = [super hittest:point withevent:event]; [self endediting:yes]; return result; }
this works, dismiss virtual keyboard when touch / scroll / swipe / pinch ... somewhere else, problem shows up.
the keyboard active or shown when touch 1 uitextfield object, touch same uitextfield object, here problem, keyboard try dismiss not completely, in middle of somewhere begin show up, doing kind of weird animation. of case in our apps, keyboard should stay still when touch same uitextfield object. there nice , simple way solve problem?
solved: finally, figure out myself. @wain, @wain's hint. check result
before invoke [self endediting:yes];
. here modified code:
- (uiview *)hittest:(cgpoint)point withevent:(uievent *)event { uiview *result = [super hittest:point withevent:event]; // can change following condition meet own needs if (![result ismemberofclass:[uitextfield class]] && ![result ismemberofclass:[uitextview class]]) { [self endediting:yes]; } return result; }
check class
of result
can limit when end editing. if hit target editable class (like text field, or switch) don't end editing session.
Comments
Post a Comment