Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS 6自动旋转混淆_Iphone_Rotation_Ios6_Autorotate - Fatal编程技术网

Iphone iOS 6自动旋转混淆

Iphone iOS 6自动旋转混淆,iphone,rotation,ios6,autorotate,Iphone,Rotation,Ios6,Autorotate,我的整个界面都在一个故事板中。如何使大多数ViewController仅支持纵向,而只有一对ViewController支持所有方向。我不明白苹果新的自动旋转系统。另外,如何使其向后兼容到iOS 5?您应该观看《基本要素》一节中有关旋转的部分 iOS中名为T Evolution of View Controller(视图控制器的T演化)的一本书详细介绍了旋转以及如何使其与各种iOS版本兼容,并提供了解释和代码示例,我对它的解释再好不过苹果了 嗯,我在这件事上有点胡思乱想。 这是我的子类NavCo

我的整个界面都在一个故事板中。如何使大多数ViewController仅支持纵向,而只有一对ViewController支持所有方向。我不明白苹果新的自动旋转系统。另外,如何使其向后兼容到iOS 5?

您应该观看《基本要素》一节中有关旋转的部分


iOS中名为T Evolution of View Controller(视图控制器的T演化)的一本书详细介绍了旋转以及如何使其与各种iOS版本兼容,并提供了解释和代码示例,我对它的解释再好不过苹果了

嗯,我在这件事上有点胡思乱想。 这是我的子类NavController.h

#import "RootVC.h"

@implementation RootVC

-(BOOL)shouldAutorotate {
    def = [NSUserDefaults standardUserDefaults];
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
    if ([def integerForKey:@"Should Rotate"] == 1) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskPortrait;
}
@end
-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger) supportedInterfaceOrientations
{
    if (self.topViewController.view.superview)
    {
        return [self.topViewController supportedInterfaceOrientations];
    }

    return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}
我只是在中的每个视图控制器上为@Should设置了一个默认旋转整数

- (void)viewWillAppear:(BOOL)animated

工作起来很有魅力

如果您使用的是本机rootViewController,则必须对其进行扩展,以优雅地支持iOS5。上述WWDC视频中提到了这一点

基本上,如果您使用的是UINavigationViewController,请扩展它并重写其-NSUIntegersupportedInterfaceOrientations方法。在这里,查看您的孩子,您只需查询旧的接口定向方法,确定应该支持什么,并返回正确的值

需要这样做才能向后兼容的原因有两个: -他们不赞成用旧的方法来旋转东西 -只有rootViewController才能获得旋转调用。父母应该为孩子决定自己需要的方向。所有这些更改都与新的AutoLayout内容相关联

扩展导航控制器后,转到情节提要->在本例中选择根控制器导航控制器->将类设置为新编写的类


HTH

在导航控制器子类中,将决策转发到堆栈中的俯视图控制器:

-(NSUInteger) supportedInterfaceOrientations {
   return [self.topViewController supportedInterfaceOrientations];
}

为此创建一个单独的故事板文件是最糟糕的做法,让它们与应用程序更新保持同步将是维护的噩梦。

下面是我用来支持iOS 5设备和iOS 6设备以及iPhone 5的一个技巧。在前缀文件中,添加以下定义

#ifdef __IPHONE_6_0 // Only do the rotation fix if we are building with iOS 6 API
@protocol DeprecatedRotationSupported
@optional
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation;
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end

#define shouldAutorotateToInterface_fixed shouldAutorotate \
{ \
    UIViewController <DeprecatedRotationSupported> *selfTyped = (UIViewController <DeprecatedRotationSupported> *) self; \
\
    if(![self respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) \
        return NO; \
    int optionCount = 0; \
    for(UIInterfaceOrientation orientation = UIInterfaceOrientationPortrait; orientation <= UIDeviceOrientationLandscapeLeft; orientation++) \
    { \
        if(![selfTyped shouldAutorotateToInterfaceOrientation:orientation]) continue; \
        if(optionCount==1) return YES; \
        optionCount++; \
    } \
    return NO; \
} \
\
- (NSUInteger)supportedInterfaceOrientations \
{ \
    UIViewController <DeprecatedRotationSupported> *selfTyped = (UIViewController <DeprecatedRotationSupported> *) self; \
\
    if(![self respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) return UIInterfaceOrientationMaskPortrait; \
    \
    NSUInteger supported = 0; \
    \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) supported |= UIInterfaceOrientationMaskPortrait; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) supported |= UIInterfaceOrientationMaskLandscapeLeft; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) supported |= UIInterfaceOrientationMaskLandscapeRight; \
    if([selfTyped shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) supported |= UIInterfaceOrientationMaskPortraitUpsideDown; \
    return supported;  \
} \
\
- (BOOL)shouldAutorotateToInterfaceOrientation
#else // We are building with the older API, leave shouldAutorotateToInterfaceOrientation alone.
#define shouldAutorotateToInterface_fixed shouldAutorotateToInterfaceOrientation
#endif // __IPHONE_6_0

然后,在使用shouldAutorotateToInterfaceOrientation的任何地方:改为使用shouldAutorotateToInterface\u fixed:

这是我的子类RootNavController.h

#import "RootVC.h"

@implementation RootVC

-(BOOL)shouldAutorotate {
    def = [NSUserDefaults standardUserDefaults];
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
    if ([def integerForKey:@"Should Rotate"] == 1) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationMaskPortrait;
}
@end
-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger) supportedInterfaceOrientations
{
    if (self.topViewController.view.superview)
    {
        return [self.topViewController supportedInterfaceOrientations];
    }

    return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

我看了两次视频。从我对它的解释中,我得出结论,我必须将navController子类化才能实现我想要的。我试过了,它对堆栈中的第一个viewController有效。我不知道如何让它在vc的底层工作。基本上我所有的vc要么会旋转,要么不会旋转。那么为什么不在每个ViewController中实现/覆盖supportedInterfaceOrientations方法,这取决于它是否必须旋转?!我做了,我用NSLog检查了一下,它被调用了。但是,无论我在第一个ViewController AutoRotate=YES中设置了什么行为,supportIngerfaceOrientation=纵向都是在导航堆栈上推送的所有其他视图控制器中发生的行为。我还用NSLog检查了另一个vc,看看他们是否检查了shouldAutorotate,并且在你的根子类中从未被调用过,你应该调用topViewController的方法,而不是返回实际值。好的,我在这个项目的早期临时做了一些准备,以保持iOS 5的兼容性,但仍然能够使用令人敬畏的新自动布局系统。我最初的故事板只是一个嵌入在navController中的视图控制器。在viewController的实现中,我检查当前的OS版本,然后呈现一个故事板。我有两个相同的,除了一个启用了自动布局。O所要做的就是将初始navController的类设置为我的RootVC,它有6行左右的新自动旋转API。我不得不说,这种方法更令人困惑,我认为苹果对此解释得很糟糕。这是最有意义的,我将实施这一点。我不知道如何使用自动布局和维护iOS 5的兼容性我写了一些关于迁移的经验-