【问题标题】:set Portrait Mode to Landscape将纵向模式设置为横向
【发布时间】:2013-10-07 12:42:55
【问题描述】:

我尝试使用类别.... 添加新文件并选择 Category 并创建子类 UINavigationController 类。

这是 .h 的类别代码

    #import <UIKit/UIKit.h>
    #import "AppDelegate.h"

    @interface UINavigationController (orientation)

    @end

code for .m file

#import "UINavigationController+orientation.h"

@implementation UINavigationController (orientation)

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{

    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    if (delegate.islandscape)
    {
        // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
        return UIInterfaceOrientationMaskLandscape;

    }
    return UIInterfaceOrientationMaskPortrait;

}
@end

在 App 委托中声明 isLandscape 以检查天气 First view controller 或 secondView Controller isLandscape is Bool.

现在 FirstViewController.m 文件我希望在 Portarit 模式下使用此代码

- (IBAction)PlayClicked:(id)sender
{
    AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];


    self.navigationController.navigationBarHidden=YES;
    delegate.islandscape=YES;

    ViewController * v=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

    [self presentViewController:v animated:NO completion:nil];


    //[self dismissViewControllerAnimated:YES completion:nil];
   [self.navigationController pushViewController:v animated:YES];

}


- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

我希望 SecondViewController 在横向模式下使用这个。

delegate.islandscape=NO;   // called transfer to Category 

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

我推荐这个 1st ViewController in Protrait and SecondViewController in Landscape Mode 和这个 Landscape Apps Xcode 5 / iOS 7 和其他但不适合我

【问题讨论】:

  • 我知道这不是 xcode 问题...但这适用于 ios6 和 ios5 但不适用于 ios7....

标签: iphone objective-c


【解决方案1】:

在 github 上看看这个项目 https://github.com/alloy/ForceOrientationTest

【讨论】:

  • 它在我的应用程序中没有工作,但我在这个演示中添加了我的项目并且工作正常
  • 我遇到了同样的问题,我通过呈现视图控制器而不是导航控制器来解决它
  • 嗨,但是当我以横向推动视图然后旋转模拟器或设备然后返回纵向视图然后视图是纵向但设备和模拟器处于横向时出现一个问题,请参阅图像
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
  • 2014-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多