ios - layout in UICollectionViewCel looks odd when perform setCollectionViewLayout -


i have 2 nib files rowrecordlayout , columnlayout respectively. enter image description here enter image description here

i register nib cells uicollectionview used later in cellforitematindexpath function. here code

 override func viewdidload() {  self.djcollectionview.registernib(uinib(nibname: "rowtemplatecell", bundle: nsbundle.mainbundle()), forcellwithreuseidentifier: "djcell")         self.djcollectionview.registernib(uinib(nibname: "columntemplatecell", bundle: nsbundle.mainbundle()), forcellwithreuseidentifier: "djcell2") } func collectionview(collectionview: uicollectionview, cellforitematindexpath     indexpath: nsindexpath) -> uicollectionviewcell {    var productcardcellpt : djcell?      if self._currentlayouttype == enum_layout.rowrecords {     reuseidentifier = "djcell"     productcardcellpt = collectionview.dequeuereusablecellwithreuseidentifier(reuseidentifier, forindexpath: indexpath) as? djcell     …     }else{     reuseidentifier = "djcell2"     productcardcellpt = collectionview.dequeuereusablecellwithreuseidentifier(reuseidentifier, forindexpath: indexpath) as? djcell     ...     }     return   productcardcellpt!     } 

and when touch on dj button. animation between transition ok except unexpected constraint inside cells

initial layout new layout

here code of transition layout

 @ibaction func action_togglelayout(sender: uibarbuttonitem) {         if _currentlayouttype == enum_layout.twocolumn {             _currentlayouttype = enum_layout.rowrecords             self.djcollectionview.setcollectionviewlayout(self._rowrecordslayout_collectionviewlayout!, animated: true, completion: { (isdone) -> void in              })         }         else{             _currentlayouttype = enum_layout.twocolumn             self.djcollectionview.setcollectionviewlayout(self._twocolumnlayout_collectionviewlayout!, animated: true, completion: { (isdone) -> void in                  }             })         }      } 

the content inside cells normal when scroll or down. solution fix ?

well problem cells displayed don't update when change layout. update when you're scrolling. doing calling collectionview.reloaddata() when layout has changed should work.

but don't think you're using collectionview correctly. layout nothing uicollectionviewcell , animation not work. don't think practice change collectionview cell class when you're changing layout of uicollectionview. should override method willtransitionfromlayout: of custom collectionviewcell , change constraints of cell here. working autolayout in portrait , landscape.

hope lead on right way.


Comments