iOS 竖屏和横屏的切换

来源:互联网 发布:天猫和淘宝哪个质量好 编辑:程序博客网 时间:2024/05/05 12:04


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

0 0
原创粉丝点击