xcode - Alternative iOS layouts for portrait and landscape using just one .xib file -


using interface builder in xcode , 1 .xib file, how can create alternate layouts when rotating between landscape , portrait orientations?

see diagram of differing layouts enter image description here

n.b. green view/area contain 3 items flowing horizontal in landscape , in portrait 3 items flow vertically within green view/area.

a way have 3 views in .xib file. first 1 normal view of viewcontroller no subviews.

then create views portrait , landscape need them. 3 have root-level views (have @ screenshot)

enter image description here

in viewcontroller, create 2 iboutlets, 1 portrait , 1 landscape view , connect them corresponding views in interface builder:

iboutlet uiview *_portraitview; iboutlet uiview *_landscapeview; uiview *_currentview; 

the third view, _currentview needed keep track of 1 of these views being displayed. create new function this:

-(void)setupviewfororientation:(uiinterfaceorientation)orientation {     [_currentview removefromsuperview];     if(uiinterfaceorientationislandscape(orientation))     {         [self.view addsubview:_landscapeview];         _currentview = _landscapeview;     }     else     {         [self.view addsubview:_portraitview];         _currentview = _portraitview;     } } 

you need call function 2 different places, first initialization:

-(void)viewdidload {     [super viewdidload];     uiinterfaceorientation interfaceorientation = [[uiapplication sharedapplication] statusbarorientation];     [self setupviewfororientation:interfaceorientation]; } 

and second orientation changes:

-(void)willrotatetointerfaceorientation:(uiinterfaceorientation)tointerfaceorientation duration:(nstimeinterval)duration {     [self setupviewfororientation:tointerfaceorientation]; } 

hope helps you!


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -