ios - UIViewController trouble in landscape mode -


i trying create app without story book , xibs. must work landscape mode only. got trouble:

http://i.stack.imgur.com/fpzkk.png

red - it's view of controller. it's looks in wrong position , not rotated. create use code in appdelegate:

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     // override point customization after application launch.     cgrect screenrect = [[uiscreen mainscreen] bounds];      self.window = [[uiwindow alloc] initwithframe:screenrect];      emulationviewcontroller* cntr = [emulationviewcontroller sharedcontroller];     [self.window addsubview:cntr.view];      [self.window makekeyandvisible];       return yes; } 

and

- (void)loadview {     cgrect screenrect = [[uiscreen mainscreen] bounds];     cgrect applicationframe = [[uiscreen mainscreen] applicationframe];     emuwindow* view = [[emuwindow alloc]  initwithframe:[[uiscreen mainscreen] bounds]];     view.backgroundcolor =[uicolor redcolor];     self.view = view; } 

it's tested on simulator ios 8. wrong?

you need make view controller root view controller, instead of this:

[self.window addsubview:cntr.view];  

... this:

self.window.rootviewcontroller = cntr; 

if don't won't automatically rotated...

then if want in landscape, can add view controller code:

-(nsuinteger) supportedinterfaceorientations {     return uiinterfaceorientationmasklandscapeleft | uiinterfaceorientationmasklandscaperight; } 

Comments