ios - Tabbed view controller, scrollToItem in collection view not working after switching tabs -
i have tabbed bar view controller. main view controller has collection view. want animate list of cells contained in array so:
// called in viewdidappear func animatenewachievements() { if let indexpath = newachievementindexpaths.first { collectionview.scrolltoitem(at: indexpath, at: .bottom, animated: true) } } // delegate method func scrollviewdidendscrollinganimation(_ scrollview: uiscrollview) { if let indexpath = newachievementindexpaths.first { if let cell = collectionview.cellforitem(at: indexpath) as? trophycollectionviewcell { cell.animate(completion: { if self.newachievementindexpaths.count > 0 { self.newachievementindexpaths.removefirst() } self.perform(#selector(self.animatenewachievements), with: nil, afterdelay: 0.4) }) } } }
as can see if cycle through index paths in newachievementindexpaths
1 one. works if interrupt process , switch tabs , return view controller animation not continue. calls collectionview.scrolltoitem(at: indexpath, at: .bottom, animated: true)
doesn't animate , delegate isn't called. if scroll table finger , leave , return screen resume animation without issues.
any ideas happening here?
i think because collection view isn't programmatically scrolling when switch view controllers.
just try adding this:
override func viewwilldisappear(_ animated: bool) { if let indexpath = newachievementindexpaths[1] { collectionview.scrolltoitem(at: indexpath, at: .bottom, animated: true) } }
this way scroll item in viewdidappear
when return view controller.
Comments
Post a Comment