IOS 6 screen rotation without using storyboard

谁说我不能喝 提交于 2019-12-30 17:57:54

问题


Anyone who's trying the newest iOS 6 beta(version 2 or 3) has the same experience of auto rotation not working?

I am not using storyboard but pure navigation control:

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navController.view];

And have:

- (BOOL)shouldAutorotateToInterfaceOrientation: ](UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}

BUT IOS has no espouse at all, works fine with all previous iOS on 3GS/4S and 4.3,5.0.5.1 simulator, but iOS 6 seems just buggy


回答1:


Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientations and shouldAutorotate methods.

Read more here.




回答2:


instead of [self.window addSubview:navController.view];

insert self.window.rootViewController = navController;




回答3:


The solution is that: Since my app is trying to support from 4.3+, I have to use the navigation controller to do every view switch.

by ios6 seems delegates to the navigation controller, I have to define my own navigation controller, and setup conditions and functions to change its rotation behaviour.

When I load a view, I then do([self.navigationCOntroller setEnableLandscape:(BOOL)false]). in that way you have full controller of your navigation controller.

NOTE: I did try override the navigation controller methods, but seems just get ignored. (This only happens to ios 6.0 as well), haven't test 6.1 yet, so not sure if it's get fixed(which please let me know if it does)



来源:https://stackoverflow.com/questions/11544382/ios-6-screen-rotation-without-using-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!