将纵向模式设置为横向

时间:2013-10-07 12:42:56

标签: iphone objective-c

我尝试使用类别.... 添加新文件并选择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以检查天气第一个视图控制器或第二个视图控制器isLandscape是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以及其他但不适用于我

1 个答案:

答案 0 :(得分:0)

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

enter image description here