uiinterfaceorientation - UICollectionView not adapting to iPad screen during rotation -
#pragma mark rotation handling methods -(void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration: (nstimeinterval)duration { nslog(@"is rotating"); // fade collectionview out [self.collectionview setalpha:0.0f]; // suppress layout errors invalidating layout [self.collectionview.collectionviewlayout invalidatelayout]; // calculate index of item collectionview displaying cgpoint currentoffset = [self.collectionview contentoffset]; self.currentindex = currentoffset.x / self.collectionview.frame.size.width; } - (void)viewwilllayoutsubviews; { [super viewwilllayoutsubviews]; uicollectionviewflowlayout *flowlayout = (id)self.collectionview.collectionviewlayout; if (uideviceorientationislandscape([[uiapplication sharedapplication] statusbarorientation])) { flowlayout.itemsize = cgsizemake(self.view.bounds.size.width, self.view.bounds.size.height); } else { flowlayout.itemsize = cgsizemake(self.view.bounds.size.width, self.view.bounds.size.height); } [flowlayout invalidatelayout]; //force elements laid out again new size } -(void)didrotatefrominterfaceorientation:(uiinterfaceorientation)frominterfaceorientation { // force realignment of cell being displayed cgsize currentsize = self.view.bounds.size; float offset = self.currentindex * currentsize.width; [self.collectionview setcontentoffset:cgpointmake(offset, 0)]; nslog(@"current bounds: %f",self.view.bounds.size.width); nsindexpath *indexpath = [nsindexpath indexpathforitem:self.currentindex insection:0]; [self.collectionview scrolltoitematindexpath:indexpath atscrollposition:uicollectionviewscrollpositionleft animated:no]; // fade collectionview in [uiview animatewithduration:0.125f animations:^{ [self.collectionview setalpha:1.0f]; }]; }
this code. want image maintain full screen , collection view conforming portrait. can see cells trying adjust, collection view not resizing. suggestions/fixes?
where set new frame collectionview? either should set in willanimaterotationtointerfaceorientation: duration:
or didrotatefrominterfaceorientation:
or if equal size of superview, set resizing mask flexible width or height.
_collectionview.autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight;
in viewwilllayoutsubviews
setting itemsize in landscape , portrait same, intended?
Comments
Post a Comment