ios - Getting UIKeyboard Height When TextField Shows -
i have couple uitextfields hidden keyboard when pops up, implemented uikeyboardwillshownotification
, uikeyboardwillhidenotification
, sent them respective methods:
- (void)keyboardwillshow:(nsnotification*)notification { cgfloat height = [[notification.userinfo objectforkey:uikeyboardframeenduserinfokey] cgrectvalue].size.height; keyboardheight = height; } - (void)keyboardwillhide:(nsnotification*)notification { cgfloat height = [[notification.userinfo objectforkey:uikeyboardframeenduserinfokey] cgrectvalue].size.height; keyboardheight = height; }
i have textfields delegating method:
//textfielddelegate - (void)textfielddidbeginediting:(uitextfield *)textfield { float keyboardoffset = [self offsetforkeyboard:textfield.frame.origin.y withheight:textfield.frame.size.height]; nslog(@"%f, %f", keyboardheight, keyboardoffset); [uiview beginanimations:nil context:nil]; [uiview setanimationduration:0.1]; self.view.frame = [global rect:self.view.frame withnewy:-[self offsetforkeyboard:textfield.frame.origin.y withheight:textfield.frame.size.height]]; [uiview commitanimations]; }
the code runs properly, when run code, keyboardwillshow:
method runs after textfielddidbeginediting:
method. because of this, keyboardheight
set 0 first time code runs, , offset calculate way off.
how can create keyboardwillshow:
method run before textfielddidbeginediting:
method? there delegate method can utilize instead?
sorry, no there's no way that. have animations or whatever keyboard handling inside notification observer. here's apple recommends , works fine me in cases i've encountered upto now.
apple's keyboard guide
ios objective-c delegates uitextfield uikeyboard
No comments:
Post a Comment