ios - Scrolling down UIScrollView when selecting upper UITextField -


i having scrollview, contentview, has 5 uitextfields. have implemented adjustforkeyboard:

func adjustforkeyboard(notification: nsnotification) {     let userinfo = notification.userinfo!      let keyboardscreenendframe = (userinfo[uikeyboardframeenduserinfokey] as! nsvalue).cgrectvalue()     let keyboardviewendframe = view.convertrect(keyboardscreenendframe, fromview: view.window)      if notification.name == uikeyboardwillhidenotification {         scrollview.contentinset = uiedgeinsetszero     } else {         scrollview.contentinset = uiedgeinsets(top: 0, left: 0, bottom: keyboardviewendframe.height, right: 0)     }      scrollview.scrollindicatorinsets = scrollview.contentinset  } 

of course have set observers:

override func viewwillappear(animated: bool) {     // add observers keyboard     let notificationcenter = nsnotificationcenter.defaultcenter()     notificationcenter.addobserver(self, selector: "adjustforkeyboard:", name: uikeyboardwillhidenotification, object: nil)     notificationcenter.addobserver(self, selector: "adjustforkeyboard:", name: uikeyboardwillchangeframenotification, object: nil) } 

it works fine when select textfields down when select upper textfield, moves few pixels. how should change method?

changing bottom contentinset not make scrollview scroll. sets buffer @ bottom, if scroll way bottom have more room scroll.

you want modify contentoffset of scrollview , animate contentoffset change. you'd this:

var contentoffset = scrollview.contentoffset contentoffset.y = contentoffset.y + (however want move) scrollview.setcontentoffset(contentoffset, animated: true) 

that let scroll both , down depending textfield selected.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -