iOS6中的纵向和横向模式 [英] Portrait and Landscape mode in iOS6
问题描述
将我的应用更新为iOS6标准时,肖像/风景消失了。当我使用Xcode 3构建时,Ir工作得很好。但现在使用最新的Xcode和最新的SDK,旋转消失了,它始终处于纵向模式。无论我在支持的界面方向中加入什么。而我之前用于旋转的代码似乎完全没有效果。
我有这些行。
When updating my app to iOS6 standard the portrait / landscape is gone. Ir worked perfectly when I was building with Xcode 3. But now using latest Xcode and latest SDK the rotation is gone and it is always in portrait mode. No matter what I put in "Supported interface Orientations". And the code I used to get rotation before seems to have no effect at all. I had these lines.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return YES;
default:
return NO;
}
}
如何更改以及如何更改以获取它再次工作?
How do I change and what do I change to get it work again?
推荐答案
首先,在AppDelegate中,写下这个。这是非常重要的
First of all, in AppDelegate, write this. THIS IS VERY IMP
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
然后,对于只需要PORTRAIT模式的UIViewControllers,编写这些函数
Then, For UIViewControllers, in which you need only PORTRAIT mode, write these functions
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
对于需要LANDSCAPE的UIViewControllers,将屏蔽更改为All。
For UIViewControllers, which require LANDSCAPE too, change masking to All.
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
现在,如果你想在Orientation改变时做一些改变,那么使用这个函数。
Now, if you want to do some changes when Orientation changes, then use this function.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
编辑:
很大程度上取决于你的UIViewController嵌入哪个控制器。
A lot depends on with which controller is your UIViewController embedded in.
例如,如果它在UINavigationController中,那么你可能需要子类UINavigationController用来覆盖这样的方向方法。
Eg, If its inside UINavigationController, then you might need to subclass that UINavigationController to override orientation methods like this.
子类UINavigationController(层次结构的顶层viewcontroller将控制方向。)确实将它设置为self.window.rootViewController 。
subclassed UINavigationController (the top viewcontroller of the hierarchy will take control of the orientation.) did set it as self.window.rootViewController.
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
从iOS 6开始,UINavigationController不会询问其UIVIewControllers定向支持。因此我们需要将其子类化。
From iOS 6, it is given that UINavigationController won't ask its UIVIewControllers for orientation support. Hence we would need to subclass it.
这篇关于iOS6中的纵向和横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!