NT_iOS笔记—iOS图片显示2_某一个界面支持横屏()

本文介绍如何在iOS应用中实现特定界面的横屏显示功能,并详细解释了如何通过修改控制器的方法来适应不同方向的屏幕旋转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章内的图片点击后需要单独显示出来,而且还需要支持横屏显示,也仅有这个界面支持横屏显示。

1.添加支持的方向

General—>Deployment info—>Device Orientation


2.创建继承UINavigationController的子类并添加如下方法:

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

3.在不需要支持横屏显示的界面添加如下方法(iOS6以上):

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}


4.在需要支持横屏的界面修改上面的方法即可。

5.由于横竖屏的切换,界面需要重新绘画,可以在如下方法中进行(iOS6以上):

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值