iPhone界面定向

iPhone界面定向,iphone,ios,objective-c,orientation,Iphone,Ios,Objective C,Orientation,在我的iphone应用程序中,我将支持的方向标记为下面的屏幕截图 但是我想阻止一些关于自动旋转的视图,因为我正在使用下面的代码(ios6) 编辑 -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)s

在我的iphone应用程序中,我将支持的方向标记为下面的屏幕截图

但是我想阻止一些关于自动旋转的视图,因为我正在使用下面的代码(ios6)

编辑

-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}


- (BOOL)shouldAutorotate
{
return NO;
 }

但视图仍在旋转,请帮助我解决此问题?

应自动旋转指针FaceOrientation
在iOS 6中不推荐使用


有关更多详细信息,请查看的答案。

应自动旋转指向器面方向在iOS 6中不推荐使用


有关更多详细信息,请查看的答案。

iOS 6.0引入了新的旋转方法,并且不调用
shouldAutorotateToInterfaceOrientation:

您需要实现这些方法以支持iOS 6.0之前的版本和iOS 6.0+版本:

// Do as many checks as you want to allow for other orientations here for pre-iOS 6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

// You can return YES here as this still checks supportedInterfaceOrientations
// before rotating, or you can return NO to 'lock' the view in whatever it's in... 
// Making sure to return the appropriate value within supportedInterfaceOrientations

- (BOOL)shouldAutorotate
{
    return YES;
}

// return supported orientations, bitwised OR-ed together

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
编辑-如果您的
UIViewController
位于
UINavigationController
的层次结构中

如果视图控制器位于
UINavigationController
的视图层次结构中,则实际会在导航控制器(而不是视图控制器)上调用旋转方法。。。在我看来,这是由苹果实现的,但下面是允许视图控制器响应这些方法的方法-

使用以下方法在
UINavigationController
上创建一个类别:

// UINavigationController+Additions.h file

@interface UINavigationController (Additions)
@end




// UINavigationController+Additions.m file

#import "UINavigationController+Additions.h"

@implementation UINavigationController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
        return [viewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [viewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end
编辑2-如果您的
UIViewController
位于
UIAbbarController
的选项卡中

如果视图控制器位于
UITabBarController
的选项卡内,则会出现相同的问题

再次,在
UITabBarController
上创建一个类别,以允许视图控制器响应:

// UITabBarController+Additions.h file

@interface UITabBarController (Additions)
@end

// UITabBarController+Additions.m file

#import "UITabBarController+Additions.h"

@implementation UITabBarController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
    return [selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [selectedViewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end
编辑3

这里还有一些关于Objective-C类别的链接:


iOS 6.0引入了新的旋转方法,并且不调用
shouldAutorotateToInterfaceOrientation:

您需要实现这些方法以支持iOS 6.0之前的版本和iOS 6.0+版本:

// Do as many checks as you want to allow for other orientations here for pre-iOS 6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

// You can return YES here as this still checks supportedInterfaceOrientations
// before rotating, or you can return NO to 'lock' the view in whatever it's in... 
// Making sure to return the appropriate value within supportedInterfaceOrientations

- (BOOL)shouldAutorotate
{
    return YES;
}

// return supported orientations, bitwised OR-ed together

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
编辑-如果您的
UIViewController
位于
UINavigationController
的层次结构中

如果视图控制器位于
UINavigationController
的视图层次结构中,则实际会在导航控制器(而不是视图控制器)上调用旋转方法。。。在我看来,这是由苹果实现的,但下面是允许视图控制器响应这些方法的方法-

使用以下方法在
UINavigationController
上创建一个类别:

// UINavigationController+Additions.h file

@interface UINavigationController (Additions)
@end




// UINavigationController+Additions.m file

#import "UINavigationController+Additions.h"

@implementation UINavigationController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
        return [viewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *viewController = [self topViewController];

    if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [viewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end
编辑2-如果您的
UIViewController
位于
UIAbbarController
的选项卡中

如果视图控制器位于
UITabBarController
的选项卡内,则会出现相同的问题

再次,在
UITabBarController
上创建一个类别,以允许视图控制器响应:

// UITabBarController+Additions.h file

@interface UITabBarController (Additions)
@end

// UITabBarController+Additions.m file

#import "UITabBarController+Additions.h"

@implementation UITabBarController (Additions)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
    {
    return [selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    }

    return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController *selectedViewController = [self selectedViewController];

    if ([selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [selectedViewController supportedInterfaceOrientations];
    }

    return [super supportedInterfaceOrientations];
}

@end
编辑3

这里还有一些关于Objective-C类别的链接:


如果您想固定特定视图的方向,请尝试以下操作

-(BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait; //IOS_6
}
编辑

-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}


- (BOOL)shouldAutorotate
{
return NO;
 }
当你有一个标签栏时,你需要对此进行调整。请看链接。希望这能有所帮助


  • 如果要固定特定视图的方向,请尝试以下操作:

    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait; //IOS_6
    }
    
    编辑

    -(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
    {
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    
    - (BOOL)shouldAutorotate
    {
    return NO;
     }
    
    当你有一个标签栏时,你需要对此进行调整。请看链接。希望这能有所帮助


  • 据我所知,你最好也写两种方法如下

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    据我所知,你最好也写两种方法如下

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    你真的想要你的方向颠倒还是只是肖像? 我为纵向构建了我的应用程序,请尝试此代码(对于纵向,如果其他,请修改)


    你真的想要你的方向颠倒还是只是肖像? 我为纵向构建了我的应用程序,请尝试此代码(对于纵向,如果其他,请修改)


    当涉及
    UINavigationController
    uitabarcontroller
    时,将
    UINavigationController
    /
    uitabarcontroller
    子类化,并覆盖支持的接口方向

     #import "UINavigationController+Orientation.h"
    
     @implementation UINavigationController (Orientation)
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
    
    -(BOOL)shouldAutorotate
    {
        return [self.topViewController shouldAutorotate];
    }
    
    @end  
    
    //对于
    UITabBarController

    #import "UITabBarController+Orientation.h"
    
    @implementation UITabBarController (Orientation)
    
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // You do not need this method if you are not supporting earlier iOS Versions
        return [self.selectedViewController  shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    @end
    
    现在,iOS容器(如UINavigationController)不会咨询其子容器以确定它们是否应该自动旋转。
    如何子类
    1.添加新文件(目标c-cocoa touch下的类别)
    2. <代码>类别
    :导航控制器上的方向
    类别
    
    3.当涉及
    UINavigationController
    uitabarcontroller
    时,将上述代码添加到
    UINavigationController+Orientation.m
    中,子类化
    UINavigationController
    覆盖支持的接口方向

     #import "UINavigationController+Orientation.h"
    
     @implementation UINavigationController (Orientation)
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
    
    -(BOOL)shouldAutorotate
    {
        return [self.topViewController shouldAutorotate];
    }
    
    @end  
    
    //对于
    UITabBarController

    #import "UITabBarController+Orientation.h"
    
    @implementation UITabBarController (Orientation)
    
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // You do not need this method if you are not supporting earlier iOS Versions
        return [self.selectedViewController  shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    @end
    
    现在,iOS容器(如UINavigationController)不会咨询其子容器以确定它们是否应该自动旋转。
    如何子类
    1.添加新文件(目标c-cocoa touch下的类别)
    2. <代码>类别
    :导航控制器上的方向
    类别
    
    3.将上述代码添加到
    UINavigationController+Orientation.m

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return(interfaceOrientation==UIInterfaceOrientationGrait);}什么版本的iOS?iOS 6.0+下不使用
    shouldAutorotateToInterfaceOrientation:
    。为此,您需要
    支持的接口方向
    方法。如果您支持5.x和6.x,那么实现这两种方法。和你一样的问题…(BOOL)应该自动旋转指向接口方向:(UIInterfaceOrientation)interfaceOrientation{return(interfaceOrientation==UIInterfaceOrientationGrait);}什么版本的iOS?
    应该是自动的