美文网首页
iOS13 横竖屏的切换

iOS13 横竖屏的切换

作者: Leo丶Dicaprio | 来源:发表于2020-07-16 10:07 被阅读0次

先吐槽下简书,本来昨天在简书中搜索到的文章https://www.jianshu.com/p/18115d353df9解决了问题。今天在来看文章没了, 作者也没了,,,,我勒个大擦。
此文章做个笔记,防止再找不到了。

项目配置中,我使用的是Portrait


截屏2020-07-16 上午10.04.04.png

appdelegate.m中

#pragma mark - 支持了竖屏和home在右侧的横屏
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    return UIInterfaceOrientationMaskPortrait |UIInterfaceOrientationMaskLandscapeRight;
}

再需要横竖屏切换的页面中

//#pragma mark - 以下3个方法横竖屏的切换,在BaseNavigationController中指定了此页面可以横屏
- (BOOL)shouldAutorotate
{
    return YES;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return UIInterfaceOrientationPortrait;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return  UIInterfaceOrientationMaskLandscapeRight |UIInterfaceOrientationMaskPortrait;
}

如果还不能实现横竖屏切换,是TabbarController和NavigationController也需要配置
注意我用的是
nav.m中

#pragma mark - 以下3个方法横竖屏的切换 是否自动旋转,返回YES可以自动旋转
- (BOOL)shouldAutorotate
{
    if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)])
    {
        return [self.topViewController shouldAutorotate];
    }
    return NO;
}

//返回支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
    return UIInterfaceOrientationMaskPortrait;
}

//这个是返回优先方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([self.topViewController respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)])
    {
        return [self.topViewController preferredInterfaceOrientationForPresentation];
    }
    return UIInterfaceOrientationPortrait;
}

tabbar.m中

#pragma mark - 以下3个方法横竖屏的切换 是否自动旋转,返回YES可以自动旋转
- (BOOL)shouldAutorotate
{
    BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
    if ([nav isKindOfClass:[BaseNavigationController class]])
    {
        return [self.selectedViewController shouldAutorotate];
    }
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
    if ([nav isKindOfClass:[BaseNavigationController class]])
    {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    BaseNavigationController *nav = (BaseNavigationController *)self.selectedViewController;
    if ([nav isKindOfClass:[BaseNavigationController class]])
    {
        return [self.selectedViewController preferredInterfaceOrientationForPresentation];
    }
    return UIInterfaceOrientationPortrait;
}

相关文章

  • ios13 横竖屏切换

    这篇文章是关于在一个页面内的横竖屏切换(网上找了一堆都不太适用,问了朋友加上自己修改结合的方法): 首先我的设备方...

  • 安卓app在清单中设置是否禁止横竖屏销毁重建

    设置横竖屏切换的代码:(按图片位置填写) 禁止横竖屏切换的代码:

  • iOS13 横竖屏的切换

    先吐槽下简书,本来昨天在简书中搜索到的文章https://www.jianshu.com/p/18115d353d...

  • [iOS]终极横竖屏切换解决方案

    [iOS]终极横竖屏切换解决方案 [iOS]终极横竖屏切换解决方案

  • Activity横竖屏切换

    横竖屏切换 activity 会被销毁 通过修改配置实现,横竖屏切换不销毁 android:configChang...

  • 横竖屏限制

    (转)当手机没有关闭横竖屏切换功能时,系统一旦触发横竖屏切换,缺省状态下,当前活动的App的界面就会进行横竖屏切换...

  • Android 横竖屏切换总结

    一.Android切换横竖屏 应用的横竖屏设置应用的横竖屏设置主要是通过Activity的screenOrient...

  • android 横竖屏切换经验总结

    横竖屏切换已经不是什么难的了,因为要适配手机横竖屏,所以特别研究了一下,再次系统的讲讲干货。主要是横竖屏切换,不重...

  • JS 与 IOS 交互-横竖屏切换

    IOS 设备横竖屏情况 一般情形 所有界面都支持横竖屏切换如果App的所有切面都要支持横竖屏的切换,那只需要勾选【...

  • 横竖屏旋转切换

    一、代码控制横竖屏切换 二、App的横竖屏切换和许多因素有关 info.plist appDelegate Tab...

网友评论

      本文标题:iOS13 横竖屏的切换

      本文链接:https://www.haomeiwen.com/subject/kvouhktx.html