swift3 - Creating UIcollectionView with Waterfall layout and self sizing cell -


i trying implement waterfalllayout self sizing cell should work ios >= 9.0 pintrest collectionviewlayout not transition difference have fixed ratio of image fields below dynamic used uistackview.

enter image description here self sizing working fine problem in changing cell origin = 15 px between cells.

so when tried flowlayout without customisation working fine except margins between cells not correct scrolling working without performance issue ios >= 9.0

after trying customizingflowlayout performance bad in ios 10 things not working while in ios 9 works fine. know apple did improvement uicollectionview me don't see improvement.

my cell:

 override func preferredlayoutattributesfitting(_ layoutattributes: uicollectionviewlayoutattributes) -> uicollectionviewlayoutattributes {     self.setneedslayout()     self.layoutifneeded()     layoutattributes.bounds.size.height = systemlayoutsizefitting(layoutattributes.size, withhorizontalfittingpriority: uilayoutpriorityrequired, verticalfittingpriority: uilayoutpriorityfittingsizelevel).height     return layoutattributes } 

my controller:

viewdidload {   layoutview = collectionview.collectionviewlayout as! customlayout         if #available(ios 10.0, *) {             self.collectionview.isprefetchingenabled = false         }         layoutview.estimateditemsize = cgsize(width:      layoutview.cellwidth, height: 200)  }  extension recipescollectionwithsortbar: uicollectionviewdatasource { func numberofsections(in collectionview: uicollectionview) -> int {     return 1 }  func collectionview(_ collectionview: uicollectionview, numberofitemsinsection section: int) -> int {     return array.count } func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell {     let cell = collectionview.dequeuereusablecell(withreuseidentifier: customcell.reuseidentifier, for: indexpath) as! customcell     return cell }  extension recipescollectionwithsortbar : uicollectionviewdelegateflowlayout {  func scrollviewdidscroll(_ scrollview: uiscrollview) {     if scrollview.bounds.maxy == scrollview.contentsize.height &&  !isloadingmorerecipes {        //         loadmore     }   } 

my customflowlayout

    override func layoutattributesforelements(in rect: cgrect) -> [uicollectionviewlayoutattributes]? {         let attrs = super.layoutattributesforelements(in: rect)         var attrscopy = [uicollectionviewlayoutattributes]()          element in attrs! (element.copy() as! uicollectionviewlayoutattributes).representedelementcategory == .cell             && element.frame.height != cachecells[element.indexpath.item]?.frame.height {             if element.indexpath.item == 0 {                 element.frame.origin.y = self.sectioninset.top                 element.frame.origin.x = self.sectioninset.left             } else if element.indexpath.item == 1 {                 element.frame.origin.y = self.sectioninset.top                 element.frame.origin.x = cachecells[0]!.frame.maxx + margin             } else {                 let previous = cachecells[element.indexpath.item - 2]                 element.frame.origin.y = previous!.frame.maxy + self.minimuminteritemspacing                 element.frame.origin.x = previous!.frame.origin.x             }             cachecells[element.indexpath.item] = element             attrscopy.append(element)         }          let values = cachecells.values.filter({ $0.frame.intersects(rect) })         return values.map({ $0 })     } 

here have many problems : 1- have huge white space @ end of collectionview because changed cell origin problem happens @ ios > 10. tried override content size

func getcontentheight() -> cgfloat {         if !cachecells.values.isempty {             let attribute = cachecells.values.max { $0.0.frame.maxy < $0.1.frame.maxy }             return attribute!.frame.maxy + sectioninset.bottom         }         return contheight     }     override var collectionviewcontentsize: cgsize {         return cgsize(width: self.cellwidth * cgfloat(columncount), height: getcontentheight())     } 

for reason ios 9 don't solution scroll stops ..

2- scrolling performance bad in ios 10 , worst in ios 9.0.

3- when load more believe or not scroll 3 or 4 times , doesn't have more items show when print log (i have 100 item collection view show 70) , when hard scrolling remembers there's more items , show them. not sure doing wrong.

it's been 2 weeks trying figure out what's wrong may having fresh eye , mind can point on problem having.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -