ios - UIScrollView does not automatically scroll to first responder -


in simple test app (no code added, storyboard), uiscrollview scrolls automatically show next text field when becomes first responder (it doesn't account keyboard height, i'm aware of fixes that). however, in more complex app, built-in scrolling never occurs. otherwise scrollview functions perfectly.

i'm coding in swift, if have suggestion in obj-c, can translate. thanks!

edit: can confirm caused removing , re-adding subviews of uiscrollview programmatically. since need functionality, suggestions how restore auto-scroll?

edit: here code of test app version, not scroll automatically. laid out views , fields storyboard, remove , re-add programmatically.

class scrollviewcontroller: uiviewcontroller { @iboutlet weak var field1: uitextfield! @iboutlet weak var field2: uitextfield! @iboutlet weak var field3: uitextfield! @iboutlet weak var field4: uitextfield! @iboutlet weak var view1: uiview! @iboutlet weak var view2: uiview! @iboutlet weak var view3: uiview! @iboutlet weak var view4: uiview! @iboutlet weak var scrollview: uiscrollview!  var fields = [uitextfield]() var views = [uiview]()  override func viewdidload() {     super.viewdidload()     fields = [field1, field2, field3, field4]     views = [view1, view2, view3, view4]     v in views {         v.removefromsuperview()     } }  override func viewwillappear(animated: bool) {     super.viewwillappear(true)     var vconstraints = "v:|"     v in views {         scrollview.addsubview(v)         scrollview.addconstraint(nslayoutconstraint(item: v, attribute: nslayoutattribute.width, relatedby: nslayoutrelation.equal, toitem: scrollview, attribute: nslayoutattribute.width, multiplier: 1, constant: 0))         let vindex = find(views, v)! + 1         vconstraints += "-8-[v\(vindex)]"     }     vconstraints += "-8-|"     scrollview.addconstraints(nslayoutconstraint.constraintswithvisualformat(vconstraints, options: nslayoutformatoptions(0), metrics: nil, views: ["v1": view1, "v2": view2, "v3": view3, "v4": view4]))     self.view.layoutifneeded() }  override func didreceivememorywarning() {     super.didreceivememorywarning() } } 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -