ios - How do I define the size of a CollectionView on rotate -


i have viewcontroller 2 collectionview controllers.

i on rotation 1 of collection views resize custom size while other remains same.

i have tried use:

- (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout  *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath   {          // adjust cell size orientation      if (uideviceorientationislandscape([[uiapplication sharedapplication] statusbarorientation])) {         return cgsizemake(170.f, 170.f);      }     return cgsizemake(192.f, 192.f); } 

however changes both collectionviews. how specific 1 collection?

heres 2 cents - because item sizes static why don't set item size on collectionviewlayout?

it quicker rather expecting collection view call delegate method every cell.

viewwilllayoutsubviews can used detection of rotation on view controllers. invalidatelayout can used on collection view layout force prepare layout again causing position elements new sizes in case.

- (void)viewwilllayoutsubviews; {     [super viewwilllayoutsubviews];     uicollectionviewflowlayout *flowlayout = (id)self.firstcollectionview.collectionviewlayout;      if (uiinterfaceorientationislandscape(uiapplication.sharedapplication.statusbarorientation)) {         flowlayout.itemsize = cgsizemake(170.f, 170.f);     } else {         flowlayout.itemsize = cgsizemake(192.f, 192.f);     }      [flowlayout invalidatelayout]; //force elements laid out again new size } 

edit: updated swift2.0 example

override func viewwilllayoutsubviews() {   super.viewwilllayoutsubviews()    guard let flowlayout = collectionview.collectionviewlayout as? uicollectionviewflowlayout else {     return   }    if uiinterfaceorientationislandscape(uiapplication.sharedapplication().statusbarorientation) {     flowlayout.itemsize = cgsize(width: 170, height: 170)   } else {     flowlayout.itemsize = cgsize(width: 192, height: 192)   }    flowlayout.invalidatelayout() } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -