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); } |
|
来源:http://www.cocoachina.com/bbs/read.php?tid-244095-page-1.html