ios - How to create separate orientation for specific view controller using objective C? -
i trying programmatically create ui orientation (portrait , landscape)
using objective c devices. here problem have multiple view controllers
. want use multiple orientation
particular view controller.
for ex: splash screen (app delegate - portrait) login screen (portrait) home screen (both)
if controlled below method app delegate root class
cant enable both orientation
home view controller
. showing black screen.
- (nsuinteger) application:(uiapplication *)application supportedinterfaceorientationsforwindow:(uiwindow *)window { return uiinterfaceorientationmaskportrait; }
you can try following implementation. here doing is, sends interfaceorientation need visible view controller app delegate. fist finds visible viewcontroler , gets supported interface orientation, if supportedinterfaceorientations method not implemented in visible view controller, return default orientation.
- (uiinterfaceorientationmask)application:(uiapplication *)application supportedinterfaceorientationsforwindow:(uiwindow *)window { uiviewcontroller *topcontroller = [self topmostviewcontroller]; if ([topcontroller respondstoselector:@selector(supportedinterfaceorientations)]) { return [topcontroller supportedinterfaceorientations]; } return uiinterfaceorientationmaskallbutupsidedown; } - (uiviewcontroller *)topmostviewcontroller { uiviewcontroller *topcontroller = self.window.rootviewcontroller; return [self topviewcontrollerwithrootviewcontroller:topcontroller]; } - (uiviewcontroller *)topviewcontrollerwithrootviewcontroller:(uiviewcontroller *)rootviewcontroller { if ([rootviewcontroller iskindofclass:[uitabbarcontroller class]]) { uitabbarcontroller* tabbarcontroller = (uitabbarcontroller*)rootviewcontroller; return [self topviewcontrollerwithrootviewcontroller:tabbarcontroller.selectedviewcontroller]; } else if ([rootviewcontroller iskindofclass:[uinavigationcontroller class]]) { uinavigationcontroller* navigationcontroller = (uinavigationcontroller*)rootviewcontroller; return [self topviewcontrollerwithrootviewcontroller:navigationcontroller.topviewcontroller];// dont use visible view controller, since return presented viewcontroller, may uialertcontroller. } else if (rootviewcontroller.presentedviewcontroller && ![rootviewcontroller.presentedviewcontroller iskindofclass:[uialertcontroller class]]) { uiviewcontroller* presentedviewcontroller = rootviewcontroller.presentedviewcontroller; return [self topviewcontrollerwithrootviewcontroller:presentedviewcontroller]; } else { return rootviewcontroller; } }
and if want display view controller orientation other uiinterfaceorientationmaskallbutupsidedown
implement following method in view controller
- (uiinterfaceorientationmask)supportedinterfaceorientations { return <whichever orientation need>; }
update:
make sure selected orientations needed initial view controller in target settings.
ref: finding topmost view controller code this answer slight modification addressing uialertcontroller presented case
Comments
Post a Comment