swift - UICollectionview custom flow layout - performance issues -
i struggling with performance issues while changing orientation of device. according apple documentation there way improve performance implementing
override func shouldinvalidatelayout(forboundschange newbounds: cgrect) -> bool and
override func invalidationcontext(forboundschange newbounds: cgrect) -> uicollectionviewlayoutinvalidationcontext the second method allows me invalidate items interested of. invalidate items ( don't wanna invalidate headers, footers. )
if return true first method performance going jump crazy, if stay implementation inside view controller :
override func viewwilltransition(to size: cgsize, coordinator: uiviewcontrollertransitioncoordinator) { super.viewwilltransition(to: size, with: coordinator) coordinator.animate(alongsidetransition: nil, completion: { _ in uiview.animate(withduration: 1.0, delay: 0.0, usingspringwithdamping: 0.5, initialspringvelocity: 0.5, options: .curvelinear, animations: { self.collectionview.collectionviewlayout.invalidatelayout() }) }) } i'll ( if have animation block ) no animations , messy stuffs - performance normal.
what best approach out of lags ?
so far i've got :
override func shouldinvalidatelayout(forboundschange newbounds: cgrect) -> bool { invalidatelayout(with: invalidationcontext(forboundschange: newbounds)) return super.shouldinvalidatelayout(forboundschange: newbounds) } override func invalidationcontext(forboundschange newbounds: cgrect) -> uicollectionviewlayoutinvalidationcontext { var context = super.invalidationcontext(forboundschange: newbounds) if // context equal items { // invalidate items } return context } thanks help!
Comments
Post a Comment