ios控制屏幕旋转

Appdelegate里添加方法,覆盖plist效果
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAll;//4个方向
}


presentViewControllerh方式

//在需要控制的viewController里边填写

单个控制的视图必须以presentViewController方式打开,才会生效
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;//横屏(home键再左或右)
    return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; //竖屏(home键再上或下)
    return UIInterfaceOrientationMaskPortrait;//home键再下
    return UIInterfaceOrientationMaskPortraitUpsideDown;//home键再上
    return UIInterfaceOrientationMaskLandscapeLeft;//home键再左
    return UIInterfaceOrientationMaskLandscapeRight;//home键再右
}




//push方式

//添加UINavigationController类别(声明,实现以下方法)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

- (BOOL)shouldAutorotate {

    return self.topViewController.shouldAutorotate;

}

- (NSUInteger)supportedInterfaceOrientations{

    return self.topViewController.supportedInterfaceOrientations;

}



//在需要控制的viewController里边填写

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return YES;

}

- (BOOL)shouldAutorotate{

    return YES;

}

- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskLandscape;

}

//页面初次显示可能会显示上一视图控制器方向

//设置默认方向(手动设置方向)

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    if([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]) {

        BOOL (*objc_msgSendTyped)(id self, SEL _cmd, int animated) = (void*)objc_msgSend;

        objc_msgSendTyped([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeRight);

    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值