ios - Scroll to scrollview page while scrollview is being resized -


i've got scrollview paging disabled. has number of subviews. each of has width constraint , constrained each other , scrollview, when subviews grow, scrollview content area grows.

when subview tapped, run following code:

var page = subview.tag  scrollviewsubviewwidthconstraint in scrollviewsubviewwidthconstraints {     //this results in subview being larger     scrollviewsubviewwidthconstraint.constant = self.view.frame.width }  uiview.animatewithduration(0.35) {     self.view.layoutifneeded() }  scrollview.pagingenabled = false scrollview.setcontentoffset(cgpoint(x: self.view.frame.width * cgfloat(page), y: 0), animated: true) 

this code intended to:

  1. resize subviews width of 'page'
  2. enable paging on scrollview
  3. scroll correct page smoothly

unfortunately not doesn't scroll correct page, seemingly because it's trying calculate amount scroll while constraints being updated, in unappealing fashion animation wise.

if change code (cutting out animation) still doesn't work:

self.view.layoutifneeded()  scrollview.pagingenabled = true scrollview.setcontentoffset(cgpoint(x: self.view.frame.width * cgfloat(page), y: 0), animated: false) 

this works, it's not animated, , it's delayed - neither of okay.

self.view.layoutifneeded()  uihelper.delay(0.1, closure: { () -> () in //helper function executes code after given delay...     self.scrollview.pagingenabled = true     scrollview.setcontentoffset(cgpoint(x: self.view.frame.width * cgfloat(page), y: 0), animated: true) }) 

maybe workaround can set contentoffset animation block

    uiview.animatewithduration(0.35) {         self.view.layoutifneeded()         scrollview.setcontentoffset(cgpoint(x: self.view.frame.width * cgfloat(page), y: 0), animated: false)     } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -