objective c - Auto Rotation iOS 8 Navigation Controller -


i have viewcontrollers managed uinavigationcontroller (push , pop). want restrict different viewcontrollers different orientations first 1 should in portrait, second in portrait, third in landscape , fourth can portrait , landscape both. set viewcontroller on isinitialviewcontroller storyboard,

- (bool) shouldautorotate{ return no; 

}

worked without problem when set navigation controller (managing these 4 views push , pop) isinitialviewcontroller storyboard, function stopped being called , autoratates. how can stop autorotating these views using uinavigationcontroller isinitialviewcontroller. use following functions depends on viewcontroller is

- (bool) shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation{ return (interfaceorientation == uideviceorientationportrait);//choose portrait or landscape}  - (bool) shouldautorotate{ return no; }  - (nsuinteger)supportedinterfaceorientations { //return uiinterfaceorientationmasklandscape; return uiinterfaceorientationmaskportrait; }  - (uiinterfaceorientation)preferredinterfaceorientationforpresentation {  //    return uiinterfaceorientationlandscapeleft | //    uiinterfaceorientationlandscaperight; return uiinterfaceorientationportrait; } 

just subclass uinavigationcontroller , override appropriate methods:

.h file:

@interface customuinavigationcontroller : uinavigationcontroller @property   bool canrotate; @end 

.m file:

@implementation customuinavigationcontroller  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view. }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }    - (nsuinteger)supportedinterfaceorientations {     return uiinterfaceorientationmaskportrait; }  - (uiinterfaceorientation)preferredinterfaceorientationforpresentation {     return uiinterfaceorientationportrait; }  - (bool)shouldautorotate {     return self.canrotate; } @end 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -