【问题标题】:iphone Orientation issue..iphone方向问题..
【发布时间】:2012-10-22 10:43:17
【问题描述】:

我遇到了关于 iphone 屏幕方向的问题。我的应用程序的基础 sdk 是 ios 6.0,部署目标是 4.3,并在 ios 5.0 和 5.1 上运行

在应用程序的 plist 文件中,我设置了 Portrait (bottom home button)Landscape (left home button)Landscape (right home button)。我正在开发一个通用应用程序。所以在每个视图的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法中,我有条件地返回portrait for iphone 和landscape for ipad。

我的导航流程是:

UINavigatinController 推送 UITableViewControler 第一个标签有 UINavigationControllerrootViewController 上一个一个推送 2 个视图。

在我最后一个 viewController 的 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法中,我返回了 YES。但是这个视图的应用程序根本没有被旋转。甚至没有调用- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 方法。 :(

我的要求是只支持一个视图控制器而不是整个应用程序的横向和纵向方向。

请帮帮我。

【问题讨论】:

    标签: iphone ios uiinterfaceorientation


    【解决方案1】:

    您可以通过视图控制器类中的此代码解决此方向问题。

    #ifdef IOS_OLDER_THAN_6
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    
           return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
    
    }
    #endif
    
    #ifdef IOS_NEWER_OR_EQUAL_TO_6
    -(BOOL)shouldAutorotate {
    
           return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations {
           return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight); //IOS_5
    }
    #endif
    

    您必须在 .pch 文件中定义此代码。

    代码:

     #define IOS_OLDER_THAN_6  ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0)
     #define IOS_NEWER_OR_EQUAL_TO_6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
    

    希望它有效。

    谢谢。

    【讨论】:

    • 谢谢,但问题是在shouldAutoratate.... 被调用之后我返回了我想要的方向,但应用程序没有进入那个方向:(
    【解决方案2】:

    对于 iOS 6,请使用 supportedInterfaceOrientationsshouldAutorotate 而不是 shouldAutorotateToInterfaceOrientation:

    - (NSUInteger) supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskLandscape; (Check for device type here and return appropriate orientations)
    }
    
    - (BOOL) shouldAutorotate {
       return YES;
    }
    

    【讨论】:

    • 感谢您的友好回复,但应用程序不仅适用于 ios6。正如我提到的,我也在 ios5 中运行应用程序
    【解决方案3】:

    你有多少个 UIViewController?也许是 2、3 或更多。

    尝试在每个视图控制器上添加代码

    - (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
    {
    NSLog(@"viewcontroller: %@", self);
    return YES;
    }
    

    你会知道,哪个视图控制器接收旋转通知。模态视图控制器似乎有问题。

    【讨论】:

    • 谢谢,但问题是在shouldAutoratate.... 被调用之后我返回了我想要的方向,但应用程序没有进入那个方向:(
    • 这是 iOS 6 的问题。对于这个看看这个grembe.wordpress.com/2012/09/19/here-is-what-i
    【解决方案4】:
     -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    
      // setFrames=CGRectMake(x, y, w, h);
    
    }
    

    【讨论】:

    • 谢谢,但问题是在shouldAutoratate.... 被调用之后我返回了我想要的方向,但应用程序没有进入那个方向:(
    【解决方案5】:

    您应该实现所有这些方法以使其适用于所有具有 ios >= 4.3 版本的设备..

    // Autorotation (iOS <= 5.x)
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
            return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationPortrait) ;
    }
    
    
    // Autorotation (iOS >= 6.0)
    
    - (BOOL) shouldAutorotate
    {
        return YES;
    }
    
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    

    【讨论】:

    • 谢谢,但问题是在shouldAutoratate.... 被调用之后我返回了我想要的方向,但应用程序没有进入那个方向:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多