xcode - iOS 7 Force Portrait Orientation When Dismissing Push -
at time halfway keeping viewcontrollera in portrait mode. this, using preferredinterfaceorientationforpresentation
this ensures viewcontrollera, when push it, in portrait mode. however, if push viewcontrollera viewcontrollerb, switch landscape mode in viewcontrollerb, and dismiss viewcontrollera, viewcontrollera can presented in landscape mode. desire continue multiple orientation support of viewcontrollerb, force viewcontrollera autorotate portrait.
also, reason shouldautorotate not appear getting called in viewcontrollera. perhaps addressing fix entire issue?
uinavigationcontroller+orientation.h category
@interface uinavigationcontroller (orientation) - (bool)shouldautorotate; - (uiinterfaceorientation)preferredinterfaceorientationforpresentation; @end
uinavigationcontroller+orientation.m category
-(bool)shouldautorotate { return [[self.viewcontrollers lastobject] shouldautorotate]; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return [[self.viewcontrollers lastobject] preferredinterfaceorientationforpresentation]; } @end
viewcontrollera.m
- (bool)shouldautorotate { return yes; } - (uiinterfaceorientation)preferredinterfaceorientationforpresentation { return uiinterfaceorientationportrait; }
i faced same problem. solution below, , in released app.
i added public property called allowviewrotation appdelegate.h:
@property (assign, nonatomic) bool allowviewrotation;
then i've implemented following call in appdelegate.m file:
- (nsuinteger)application:(uiapplication *)application supportedinterfaceorientationsforwindow:(uiwindow *)window{ if(ui_user_interface_idiom() == uiuserinterfaceidiompad) { // if ipad return uiinterfaceorientationmaskall; } if (self.allowviewrotation) { return uiinterfaceorientationmaskallbutupsidedown; } else { return uiinterfaceorientationmaskportrait; } }
now in viewcontrollera set allowviewrotation property no
((appdelegate*)[uiapplication sharedapplication].delegate).allowviewrotation = no;
and in viewcontrollerb set allowviewrotation property yes
((appdelegate*)[uiapplication sharedapplication].delegate).allowviewrotation = yes;
note: make sure enable proper device orientation in deployment info
hope helps!
Comments
Post a Comment