iphone - Allow change of orientation to landscape for only one tab in UITabViewController -


is possible? how might accomplish this?

not possible according apple docs.

the word possible may need asterisk it. looks apple didn't envision (or want) doing this. but, depending on requirements are, there may workaround.

disclaimer: kind of hack. i'm not claiming ui, trying show eli what's possible.

i built example, starting xcode template building tabbed application. has 2 view controllers: firstviewcontroller , secondviewcontroller. decided make firstviewcontroller landscape-only view. in interface builder (xcode ui design mode), set orientation of firstviewcontroller's view landscape, , made size 480 wide 251 high (i'm assuming iphone/ipod here).

solution

now, seems necessary have tab bar's view controllers claim support autorotation portrait , landscape. example:

- (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation {     // return yes supported orientations     return (interfaceorientation != uiinterfaceorientationportraitupsidedown); } 

so, both view controllers have same code. however, in firstviewcontroller override willanimatetointerfaceorientation:duration: , undo uiviewcontroller infrastructure does, 1 landscape-only view controller.

firstviewcontroller.m:

- (void)willanimaterotationtointerfaceorientation:(uiinterfaceorientation)interfaceorientation duration:(nstimeinterval)duration {     [super willanimaterotationtointerfaceorientation:interfaceorientation duration:duration];      cgaffinetransform viewrotation;     cgrect frame;      if (uiinterfaceorientationislandscape(interfaceorientation)) {         viewrotation = cgaffinetransformidentity;         // todo: change dynamically account status bar , tab bar height         frame = cgrectmake(0, 0, 480, 320 - 20 - 49);             } else {         viewrotation = cgaffinetransformmakerotation(m_pi_2);         // todo: change dynamically account status bar , tab bar height         frame = cgrectmake(0, 0, 320, 480 - 20 - 49);             }      // undo rotation uiviewcontroller wants do, view heirarchy     [uiview beginanimations:@"unrotation" context: null];     [uiview setanimationduration: duration];      self.view.transform = viewrotation;     self.view.frame = frame;      [uiview commitanimations]; } 

what tab bar rotate device. that's requirement, dual orientation views (e.g. secondviewcontroller) autorotation. but, actual view content of firstviewcontroller not rotate. stays in landscape orientation, no matter how user turns device. so, maybe that's partially enough you?

also of note:

1) changed app's info plist file set initial orientation landscape (since firstviewcontroller landscape one):

<key>uisupportedinterfaceorientations</key> <array>     <string>uiinterfaceorientationportrait</string>     <string>uiinterfaceorientationlandscapeleft</string>             <string>uiinterfaceorientationlandscaperight</string> </array> <key>uiinterfaceorientation</key> <string>uiinterfaceorientationlandscaperight</string> 

2) in firstviewcontroller.xib, set main/parent uiview not autoresize subviews. depending on view hierarchy, may want change property in other child views, too. can experiment setting.

now, available size landscape view change little bit, status bar , tab bar rotated. so, may need adjust layout little bit. but, basically, still wide view showing landscape content, no matter how user holds device.

results

watch youtube demo of running app


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -