zoukankan      html  css  js  c++  java
  • iOS 15系统导航栏适配

    热烈欢迎,请直接点击!!!

    进入博主App Store主页,下载使用各个作品!!!

    注:博主将坚持每月上线一个新app!!!

    iOS 15的系统导航栏背景默认静止时隐藏,得页面能滑动且有内容经过导航栏区域才会显示...

    iOS15默认样式.GIF

    解决方法

    iOS 15后,需要手动设置UINavigationBarscrollEdgeAppearancestandardAppearance属性才行。

    // OC
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        if (@available(iOS 15.0, *)) {
            UINavigationBar *navigationBar = [UINavigationBar appearance];
            
            UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
            scrollEdgeAppearance.backgroundColor = UIColor.redColor;
            navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
            
            UINavigationBarAppearance *standardAppearance = [[UINavigationBarAppearance alloc] init];
            standardAppearance.backgroundColor = UIColor.greenColor;
            navigationBar.standardAppearance = standardAppearance;
        }
        
        return YES;
    }
    // Swift
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        if #available(iOS 15.0, *) {
            let navigationBar = UINavigationBar.appearance()
    
            navigationBar.scrollEdgeAppearance = {
                let appearance = UINavigationBarAppearance()
                appearance.backgroundColor = .red
                return appearance
            }()
    
            navigationBar.standardAppearance = {
                let appearance = UINavigationBarAppearance()
                appearance.backgroundColor = .green
                return appearance
            }()
        }
        
        return true
    }

    设置后的样式.GIF

    从效果上看的出:

    • scrollEdgeAppearance:是处于顶部时的背景
    • standardAppearance:是滑动后的背景

    更多的自定义效果都可以在对应的UINavigationBarAppearance实例里面设置其属性。

    如果想统一样式,scrollEdgeAppearancestandardAppearance都设置同一个appearance即可(不设置任何属性则是默认的毛玻璃效果):

    // OC
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        if (@available(iOS 15.0, *)) {
            UINavigationBar *navigationBar = [UINavigationBar appearance];
            
            UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
            navigationBar.scrollEdgeAppearance = appearance;
            navigationBar.standardAppearance = appearance;
        }
        
        return YES;
    }
    // Swift
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        if #available(iOS 15.0, *) {
            let navigationBar = UINavigationBar.appearance()
    
            let appearance = UINavigationBarAppearance()
            navigationBar.scrollEdgeAppearance = appearance
            navigationBar.standardAppearance = appearance
        }
    
        return true
    }

    以前的样式.GIF

  • 相关阅读:
    反转链表——临时变量的妙用
    C++指针学习(2)
    统计英文文本中的词频
    灵活的C++
    编程之美 NIM(1)扩展问题
    深度探索C++对象模型读书笔记(1)
    irrlicht1.7.0(2):基础接口
    关于裁剪空间与投影变换矩阵的推导
    irrlicht1.7.0(1):irrTypes.h
    【转】每天拿两个小时来浪费(文/王路)
  • 原文地址:https://www.cnblogs.com/strengthen/p/15702105.html
Copyright © 2011-2022 走看看