GithubHelp home page GithubHelp logo

l1dan / nxnavigationextension Goto Github PK

View Code? Open in Web Editor NEW
151.0 5.0 13.0 16.33 MB

🔥 Lightweight, simple, and easy-to-use UINavigationBar library.

License: MIT License

Ruby 0.73% Objective-C 90.11% Swift 9.16%
swiftui uinavigationbar uinavigationcontroller navigationview ios iosnavigation

nxnavigationextension's People

Contributors

l1dan avatar wangjian201314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nxnavigationextension's Issues

OC的demo没了

问题描述

ℹ 替换这一行用于描述你的需求或者建议

是否通用

ℹ 如果不通用请说明一定要添加的理由

关于nx_navigationBarBackgroundImage、nx_navigationBarBackgroundColor

问题描述

问题一:我设定了nx_navigationBarBackgroundImage,但发现图片异常放大,请问我该设定什么来达到正确的大小?亦或是图片尺寸是否有限定?

问题二:我想要在TableView滚动时,替换导航栏颜色,除了自行计算contentOffset之外,我该怎么调用NXNavigationExtension来设定我要改变的颜色?

谢谢您!

xcode 15 运行ios17设备程序闪退

运行报错 Thread 1: "A trait environment returned a trait collection with unspecified values for traits that are not allowed to be unspecified. This is a serious application bug and will cause undefined behavior. This issue may be caused by your class overriding the traitCollection property getter, which is not supported. Make sure to use the appropriate API if you are trying to override traits. Trait Environment: <UITabBarSwappableImageView: 0x116794170; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; tintColor = UIExtendedGrayColorSpace 0.572549 0.85; image = <UIImage:0x6000030173c0 CGImage anonymous; (24 24)@3>; layer = <CALayer: 0x60000031b0c0>>; Trait Collection: <UITraitCollection: 0x11645fb60; HorizontalSizeClass = Compact, PreferredContentSizeCategory = L>"

关于新SwiftUI接入的问题

新版SwiftUI在项目中已经不再使用AppDelegate了,取而代之的是

import SwiftUI

@main
struct xxxxxApp: App {
    var body: some Scene {
        WindowGroup {
            XxxxView()
        }
    }
    
}

请问这种结构下如何接入NXNavigation呢?初学SwiftUI还望不吝赐教。

设置 `edgesForExtendedLayout = UIRectEdge(rawValue: 0)` 属性产生的一些已知问题

  1. 在 UIViewController 中设置 edgesForExtendedLayout = UIRectEdge(rawValue: 0) 属性,并且使用 IQKeyboardManager 框架的同时键盘没有收起,此时返回上级页面 NXNavigationBar 会出现错位的现象。这是 IQKeyboardManager 框架本身处理这种情况就有问题(设置 edgesForExtendedLayout = UIRectEdge(rawValue: 0) 属性,键盘没收起时返回上级页面导致界面下移的问题),NXNavigationExtension 框架内部无法处理这种情况(其实已经最大程度适配 IQKeyboardManager 框架)。

解决方法:

  • 不要设置edgesForExtendedLayout = UIRectEdge(rawValue: 0),保持 edgesForExtendedLayout 默认值即可。
  • 不使用 IQKeyboardManager 框架(或者在使用的 UIViewController 中暂时禁用 IQKeyboardManager 框架)。
  • 在 UIViewController 中不使用 UITextField/UITextView 等需要弹出键盘的控件。
  1. 在 UIViewController 中设置 edgesForExtendedLayout = UIRectEdge(rawValue: 0) 属性,并且使用 NXNavigationBar 本身或者 contentView 中添加需要用户交互的控件时,里面添加的控件将无法接受到用户事件的响应(控件展示没有问题),但是添加没有用户交互事件的控件是不受限制的,比如在 ViewController04_CustomNavigationBar 中设置 edgesForExtendedLayout = UIRectEdge(rawValue: 0) 属性时,NXNavigationBar 上面的按钮将无法点击。

解决方法:

  • 不要设置edgesForExtendedLayout = UIRectEdge(rawValue: 0),保持 edgesForExtendedLayout 默认值即可。
  • 不要在 NXNavigationBar 本身或者 contentView 中添加需要用户交互的控件。

pod 'NXNavigationExtension/SwiftUI'报错

使用pod安装swift版本报错,xocde是最新版本、pod是最新版本、项目最低值iOS10
[!] CocoaPods could not find compatible versions for pod "NXNavigationExtension/SwiftUI":
In Podfile:
NXNavigationExtension/SwiftUI

Specs satisfying the NXNavigationExtension/SwiftUI dependency were found, but they required a higher minimum deployment target.

请问大神怎么解决?我看文档上4.x版本的最低支持是iOS9.0。

全局设置不生效

NXNavigationConfiguration.default.viewControllerPreferences.enableFullScreenInteractivePopGesture = true
NXNavigationConfiguration.default.navigationBarAppearance.backgroundColor = .white
这两设置都不生效

FAQ 常见问题

Q:iOS14 及之后的版本为什么注册了 UIImagePickerControllerPHPickerViewController 类之后还是无法修改导航栏的外观?

A:因为 UIImagePickerControllerPHPickerViewController 里面的 UINavigationBar 是隐藏的,NXNavigationBar 会跟随系统导航栏隐藏与显示,所以无法修改(iOS14 之前系统的 UIImagePickerController 是可以修改的)。另外 PHPickerViewController 其实是一个 UIViewController 的子类,你既可以用 push 的方式显示控制器也可以用 present 的方式显示控制器,他们有个共同特点:使用的都是一个 “假” 的导航栏。


Q:为什么 iOS13 之前使用 self.navigationItem.searchController 设置的 UISearchBar 无法跟随导航栏的变化而变化,iOS13 之后的却可以呢?

A:因为在 iOS13 之前导航栏中不包含 UISearchBar,iOS13 之后导航栏才包含 UISearchBar 的。具体使用请参考示例代码


Q:如何解决 UIScrollViewUIPageViewController 全屏手势冲突?

A:使用 UIScrollViewUIPageViewController 全屏手势冲突解决方案。


Q:为什么 NXNavigationExtension 框架不包含控制器的转场动画功能?

A:原则就是尽可能的保持框架的简单轻量,将更多的精力花在框架本身的稳定性上,尽可能地使用系统原有功能。转场动画功能并不适用于所有业务场景,另外也不属于这个框架的功能。如果有转场动画的需求需要开发者自己实现,也可以参考VCTransitionsLibrary,或者参考示例代码


Q:为什么导航栏的系统返回按钮箭头和自定义返回按钮箭头的位置不一致?

A:因为导航栏的系统返回按钮是用 self.navigationItem.backBarButtonItem 属性来设置的。而自定义返回按钮是用 self.navigationItem.leftBarButtonItem 属性来设置的,他们的位置本来就不一样。当然你可以使用系统返回按钮,通过 (nx_)useSystemBackButton 属性设置是否使用系统返回按钮,再配合 (nx_)systemBackButtonTitle 属性设置系统返回按钮的标题。还可以通过 (nx_)backImageInsets 或者 (nx_)landscapeBackImageInsets 属性来控制自定义返回按钮图片的偏移量。

  • 返回按钮箭头在切图里尽量靠左而不要居中,右边可以保留透明背景。
  • 使用 nx_backButtonCustomView 属性自定义返回按钮时就需要开发者自己来修正箭头的偏移量了。

返回时导航栏会闪一下默认颜色

发生什么问题?

返回时导航栏会闪一下默认颜色

期望如何改进此问题?

预期返回上一页时导航栏颜色不会闪。

Demo 中是否出现这个问题?

Demo 没跑起来

额外信息(可选)

NXNavigationExtension 版本:4.1.6
Xcode 版本:14.3.1
运行平台:iOS 模拟器,版本 15.0
截图、示例代码等:

// NavigationDemoApp.swift
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        var classes: [AnyClass] = []
        if #available(iOS 15.0, *) {
            classes = [
                NSClassFromString("SwiftUI.SplitViewNavigationController"),
                NSClassFromString("SwiftUI.UIKitNavigationController"),
            ].compactMap { $0 }
        } else {
            classes = [
                NSClassFromString("SwiftUI.SplitViewNavigationController"), // iOS14
            ].compactMap { $0 }
        }

        let defaultConfiguration = NXNavigationConfiguration.default
        defaultConfiguration.registerNavigationControllerClasses(classes) { navigationController, configuration in
            // Configure
            navigationController.nx_applyFilterNavigationVirtualWrapperViewRuleCallback(NXNavigationVirtualView.configureWithDefaultRule(for:))
            return configuration
        }
        defaultConfiguration.navigationBarAppearance.backgroundColor = .red

        return true
    }
    
}

@main
struct NavigationDemoApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}


// ContentView.swift
import SwiftUI
import NXNavigationExtension

struct DestinationView: View {
    @State private var context: NXNavigationRouter.Context = NXNavigationRouter.Context(routeName: "/destinationView")

    var body: some View {
        Button {
            // NXNavigationRouter.of(context).pop()
            NXNavigationRouter.of(context /* /destinationView */).popUntil("/contentView")
        } label: {
            Text("Pop")
                .padding()
        }
        .useNXNavigationView(context: $context, onPrepareConfiguration: { configuration in
            configuration.navigationBarAppearance.useSystemBackButton = true
        })
    }

}

struct ContentView: View {
    @State private var context: NXNavigationRouter.Context = NXNavigationRouter.Context(routeName: "/contentView")

    var body: some View {
        NavigationView {
            NavigationLink { // 1. 使用 NavigationView 包装
                DestinationView()
            } label: {
                Text("Push")
                    .padding()
            }
        }
        .navigationViewStyle(.stack) // 2. 使用 StackNavigationViewStyle 风格
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}


// SubView.swift
import SwiftUI
import NXNavigationExtension

struct SubView: View {
    @State private var context: NXNavigationRouter.Context = NXNavigationRouter.Context(routeName: "/destinationView")

       var body: some View {
           Button {
               // NXNavigationRouter.of(context).pop()
               NXNavigationRouter.of(context /* /destinationView */).popUntil("/contentView")
           } label: {
               Text("Pop")
                   .padding()
           }
           .useNXNavigationView(context: $context, onPrepareConfiguration: { configuration in
               // `DestinationView` NavigationView backgroundColor
               configuration.navigationBarAppearance.backgroundColor = .red
           })
       }
}

struct SubView_Previews: PreviewProvider {
    static var previews: some View {
        SubView()
    }
}

屏幕录制2023-08-18 22 35 24

在Swiftui中隐藏导航栏

发生什么问题?

在Swiftui中将导航栏设为透明,但是布局依然留出了导航栏的间距

  configuration.navigationBarAppearance.backgroundColor = .clear
  configuration.navigationBarAppearance.shadowColor = .clear

期望如何改进此问题?

隐藏这块留白

Demo 中是否出现这个问题?

无此场景

额外信息(可选)

NXNavigationExtension 版本:
4.1.1
Xcode 版本:
Version 13.4.1 (13F100)
运行平台:
ios模拟器
截图、示例代码等:
image
image

异常卡死

在集成最新版本4.2.3 后,触发一个异常问题,偶尔 会出现界面跳转在执行 nav.pushxxx 导致界面卡死,进入后台然后再切回到前台才能正常显示push 之后的页面,nav在调用push 方法时候,没有时候 nx_pushxxx 方法,而是使用系统的方法,从上一个大版本4.1.6时候一直都使用的这个方法,没有任何问题,最近适配新版本后,突然才出现该问题。

关于 NXNavigationBar 导航栏返回按钮问题

在导航栏的topViewController 中,调用 .pushViewController(VC1, animated: true) 进入 一个新的控制器(假设VC1),如果在此同时将导航栏的ViewControllers数组手动改变(移除一个控制器),会出现一个奇怪的现象,在push之后的VC1 页面,自定义的返回按钮 navigationItem.leftBarButtonItem 未正常显示出来,在此同时会显示一个应该是NXNavgationExtension 内部实现的一个返回按钮,并且我在VC1中实现nx_useSystemBackButton = false 的逻辑,也无法解决这个问题。

这里有一段伪代码:
let topViewController = navController.topViewController
let vc1 = ViewController()
topViewController.navigationController?.pushViewController(vc1, animated: true)
// 这里是将当前控制器移除
topViewController.navigationController?.viewControllers.remove(topViewController)
⭐️:这样做的目的是,在返回的时候,不显示上一个控制器

在iOS16上,使用 NavigationStack ,不同的界面导航栏颜色会有bug

发生什么问题?

ℹ 替换这一行用于描述发生什么问题。

期望如何改进此问题?

ℹ 替换这一行用于描述如何改进此问题。

Demo 中是否出现这个问题?

ℹ 替换这一行用于回答“是”或“否”。

额外信息(可选)

NXNavigationExtension 版本:
Xcode 版本:
运行平台:
截图、示例代码等:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.