Adjust Keyboard to show the content behind it in IOS -
i have form in vc . in form there field , textviews. when user click text area keyboard popup , , user start typing on it. issue coming textview hides behind keyboard , user can't see he/she writing. there way user can not issue? screen looks
i suggest move views when keyboard appears , down when keyboard disappears. if want so:
you need scrollview if contents have not fit in iphone screen. (if adding scrollview superview of components. make textfield scroll when keyboard comes up, it's not needed.) showing textfields without being hidden keyboard, standard way move up/down view having textfields whenever keyboard shown. here sample code:
#define koffset_for_keyboard 80.0 -(void)keyboardwillshow { // animate current view out of way if (self.view.frame.origin.y >= 0) { [self setviewmovedup:yes]; } else if (self.view.frame.origin.y < 0) { [self setviewmovedup:no]; } } -(void)keyboardwillhide { if (self.view.frame.origin.y >= 0) { [self setviewmovedup:yes]; } else if (self.view.frame.origin.y < 0) { [self setviewmovedup:no]; } } -(void)textfielddidbeginediting:(uitextfield *)sender { if ([sender isequal:mailtf]) { //move main view, keyboard not hide it. if (self.view.frame.origin.y >= 0) { [self setviewmovedup:yes]; } } } //method move view up/down whenever keyboard shown/dismissed -(void)setviewmovedup:(bool)movedup { [uiview beginanimations:nil context:null]; [uiview setanimationduration:0.3]; // if want slide view cgrect rect = self.view.frame; if (movedup) { // 1. move view's origin text field hidden come above keyboard // 2. increase size of view area behind keyboard covered up. rect.origin.y -= koffset_for_keyboard; rect.size.height += koffset_for_keyboard; } else { // revert normal state. rect.origin.y += koffset_for_keyboard; rect.size.height -= koffset_for_keyboard; } self.view.frame = rect; [uiview commitanimations]; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; // register keyboard notifications [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillshow) name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillhide) name:uikeyboardwillhidenotification object:nil]; } - (void)viewwilldisappear:(bool)animated { [super viewwilldisappear:animated]; // unregister keyboard notifications while not visible. [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] removeobserver:self name:uikeyboardwillhidenotification object:nil]; }
Comments
Post a Comment