ios - tableView vs. scrollView behavior when keyboard appears -


if textfield opens keyboard , textfield member of tableview, able scroll tableview able see last item, , keyboard not hide item.

enter image description here

how? uitableview inherited uiscrollview. guess opening keyboard increases content offset? right?

if textfield part of scrollview, not tableview, effect not occur, , keyboard can hide out other controls positioned lower parts of scrollview.

if want see same effect scrollview tableview, should set content offset manually?

enter image description here

yes have set content offset manually .

first register notification

nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillshow:", name:uikeyboardwillshownotification, object: nil) nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillhide:", name:uikeyboardwillhidenotification, object: nil) 

and in observer methods.

func textfieldshouldreturn(textfield: uitextfield) -> bool {     textfield.resignfirstresponder()     return true }  func keyboardwillshow(notification:nsnotification){      var userinfo = notification.userinfo!     var keyboardframe:cgrect = (userinfo[uikeyboardframebeginuserinfokey] as! nsvalue).cgrectvalue()     keyboardframe = self.view.convertrect(keyboardframe, fromview: nil)      var contentinset:uiedgeinsets = self.scrollview.contentinset     contentinset.bottom = keyboardframe.size.height     self.scrollview.contentinset = contentinset }  func keyboardwillhide(notification:nsnotification){      var contentinset:uiedgeinsets = uiedgeinsetszero     self.scrollview.contentinset = contentinset } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -