iOS 豎屏和橫屏的切換


1.只支持一種方向,直接在工程 --- target — general 上直接設置某一個方向就行。


2.要是支持多個方向,在general上設置好支持的方向,然後單獨寫個基類,把需要轉向的類繼承這個基類就好,然後設置方向


.h

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

@property(nonatomic)NSUInteger orientation; 


.m

 
#import "CustomNavigationController.h"

@interface CustomNavigationController ()

@end

@implementation CustomNavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(BOOL)shouldAutorotate
{
    return NO;
    
}


-(NSUInteger)supportedInterfaceOrientations{
    //return UIInterfaceOrientationMaskLandscapeRight;
    return self.orietation;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != self.orietation);


  orientation:用來設置方向

來源:http://www.cocoachina.com/bbs/read.php?tid-244095-page-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章