Skip to content

Commit

Permalink
build: 最低支持iOS版本提升到iOS11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxiang committed May 23, 2022
1 parent 4dbdd38 commit d5900bd
Show file tree
Hide file tree
Showing 22 changed files with 424 additions and 144 deletions.
4 changes: 2 additions & 2 deletions EachNavigationBar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EachNavigationBar'
s.version = '1.15.3'
s.version = '1.16.0'
s.summary = 'A custom navigation bar of UIViewController.'
s.homepage = 'https://github.com/Pircate/EachNavigationBar'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand All @@ -10,5 +10,5 @@ Pod::Spec.new do |s|
s.resource_bundles = { 'EachNavigationBar' => ['EachNavigationBar/Assets/*.xcassets'] }
s.frameworks = 'UIKit'
s.swift_versions = ['5.1', '5.2', '5.3']
s.ios.deployment_target = '10.0'
s.ios.deployment_target = '11.0'
end
3 changes: 0 additions & 3 deletions EachNavigationBar/Classes/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,17 @@ extension UINavigationController {

public extension UINavigationController.Configuration {

@available(iOS 11.0, *)
/// Padding of navigation bar content view.
var layoutPaddings: UIEdgeInsets {
get { _layoutPaddings }
set { _layoutPaddings = newValue }
}

@available(iOS 11.0, *)
var prefersLargeTitles: Bool {
get { _prefersLargeTitles }
set { _prefersLargeTitles = newValue }
}

@available(iOS 11.0, *)
var largeTitle: LargeTitle {
get { _largeTitle }
set { _largeTitle = newValue }
Expand Down
20 changes: 7 additions & 13 deletions EachNavigationBar/Classes/EachNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class EachNavigationBar: UINavigationBar {
}
didSet {
frame.size.height = barHeight + _additionalHeight
viewController?.adjustsSafeAreaInsetsAfterIOS11()
viewController?.adjustsSafeAreaInsets()
}
}

Expand Down Expand Up @@ -64,7 +64,6 @@ open class EachNavigationBar: UINavigationBar {
}
}

@available(iOS 11.0, *)
/// Padding of navigation bar content view.
open var layoutPaddings: UIEdgeInsets {
get { _layoutPaddings }
Expand Down Expand Up @@ -131,7 +130,7 @@ extension EachNavigationBar {
changed.insert(\.isHidden)
}
didSet {
viewController?.adjustsSafeAreaInsetsAfterIOS11()
viewController?.adjustsSafeAreaInsets()
}
}

Expand Down Expand Up @@ -210,7 +209,6 @@ extension EachNavigationBar {
}
}

@available(iOS 11.0, *)
open override var prefersLargeTitles: Bool {
get { return super.prefersLargeTitles }
set {
Expand All @@ -226,7 +224,6 @@ extension EachNavigationBar {
}
}

@available(iOS 11.0, *)
open override var largeTitleTextAttributes: [NSAttributedString.Key : Any]? {
get { return super.largeTitleTextAttributes }
set {
Expand Down Expand Up @@ -271,9 +268,10 @@ extension EachNavigationBar {
}

var _additionalHeight: CGFloat {
if #available(iOS 11.0, *) {
if isLargeTitleShown { return 0 }
guard !isLargeTitleShown else {
return 0
}

return additionalHeight
}

Expand Down Expand Up @@ -310,7 +308,6 @@ private extension EachNavigationBar {
return viewController?.navigationController?.navigationBar
}

@available(iOS 11.0, *)
var contentView: UIView? {
if let contentView = _contentView { return contentView }

Expand All @@ -321,7 +318,6 @@ private extension EachNavigationBar {
return _contentView
}

@available(iOS 11.0, *)
var isLargeTitleShown: Bool {
return prefersLargeTitles && viewController?._navigationItem.largeTitleDisplayMode != .never
}
Expand All @@ -341,12 +337,10 @@ private extension EachNavigationBar {
height: bounds.height + barMinY
)

adjustsLayoutMarginsAfterIOS11()
adjustsLayoutMargins()
}

func adjustsLayoutMarginsAfterIOS11() {
guard #available(iOS 11.0, *) else { return }

func adjustsLayoutMargins() {
layoutMargins = .barLayoutMargins

guard let contentView = contentView else { return }
Expand Down
1 change: 0 additions & 1 deletion EachNavigationBar/Classes/EachNavigationItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class EachNavigationItem: UINavigationItem {
didSet { viewController?.navigationItem.title = title }
}

@available(iOS 11.0, *)
override var largeTitleDisplayMode: UINavigationItem.LargeTitleDisplayMode {
get { super.largeTitleDisplayMode }
set {
Expand Down
2 changes: 0 additions & 2 deletions EachNavigationBar/Classes/UINavigationBar+Sugar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public extension UINavigationBar {
setTitleColor(color.withAlphaComponent(alpha))
}

@available(iOS 11.0, *)
func setLargeTitleAlpha(_ alpha: CGFloat) {
let color = largeTitleTextAttributes?[.foregroundColor] as? UIColor ?? defaultTitleColor
setLargeTitleColor(color.withAlphaComponent(alpha))
Expand All @@ -41,7 +40,6 @@ private extension UINavigationBar {
}
}

@available(iOS 11.0, *)
func setLargeTitleColor(_ color: UIColor) {
if var largeTitleTextAttributes = largeTitleTextAttributes {
largeTitleTextAttributes[.foregroundColor] = color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ extension UINavigationController {

bar.adjustsLayout()

topViewController?.adjustsSafeAreaInsetsAfterIOS11()
topViewController?.adjustsSafeAreaInsets()
}

open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

guard #available(iOS 11.0, *), _configuration.isEnabled else { return }
guard _configuration.isEnabled else { return }

topViewController?._navigationBar.adjustsLayout()
}
Expand Down
52 changes: 20 additions & 32 deletions EachNavigationBar/Classes/UIViewController+EachNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,15 @@ extension UIViewController {
guard let navigationBar = navigationController?.navigationBar else { return }
navigationBar.barStyle = _navigationBar.superBarStyle
navigationBar.isHidden = _navigationBar.isHidden
if #available(iOS 11.0, *) {
adjustsSafeAreaInsetsAfterIOS11()
navigationItem.title = _navigationItem.title
navigationItem.largeTitleDisplayMode = _navigationItem.largeTitleDisplayMode
navigationBar.prefersLargeTitles = _navigationBar.prefersLargeTitles
navigationBar.largeTitleTextAttributes = _navigationBar.largeTitleTextAttributes
}
adjustsSafeAreaInsets()
navigationItem.title = _navigationItem.title
navigationItem.largeTitleDisplayMode = _navigationItem.largeTitleDisplayMode
navigationBar.prefersLargeTitles = _navigationBar.prefersLargeTitles
navigationBar.largeTitleTextAttributes = _navigationBar.largeTitleTextAttributes
view.bringSubviewToFront(_navigationBar)
}

func adjustsSafeAreaInsetsAfterIOS11() {
guard #available(iOS 11.0, *) else { return }

func adjustsSafeAreaInsets() {
let height = _navigationBar.additionalView?.frame.height ?? 0
additionalSafeAreaInsets.top = _navigationBar.isHidden
? -view.safeAreaInsets.top
Expand Down Expand Up @@ -137,11 +133,9 @@ private extension EachNavigationBar {
self.shadow = shadow
}

if #available(iOS 11.0, *) {
layoutPaddings = configuration.layoutPaddings
prefersLargeTitles = configuration.prefersLargeTitles
largeTitleTextAttributes = configuration.largeTitle.textAttributes
}
layoutPaddings = configuration.layoutPaddings
prefersLargeTitles = configuration.prefersLargeTitles
largeTitleTextAttributes = configuration.largeTitle.textAttributes

// 清空修改记录
changed.removeAll()
Expand Down Expand Up @@ -200,16 +194,14 @@ private extension EachNavigationBar {
}
}

if #available(iOS 11.0, *) {
if !changed.contains(\.layoutPaddings) {
layoutPaddings = configuration.layoutPaddings
}
if !changed.contains(\.prefersLargeTitles) {
prefersLargeTitles = configuration.prefersLargeTitles
}
if !changed.contains(\.largeTitleTextAttributes) {
largeTitleTextAttributes = configuration.largeTitle.textAttributes
}
if !changed.contains(\.layoutPaddings) {
layoutPaddings = configuration.layoutPaddings
}
if !changed.contains(\.prefersLargeTitles) {
prefersLargeTitles = configuration.prefersLargeTitles
}
if !changed.contains(\.largeTitleTextAttributes) {
largeTitleTextAttributes = configuration.largeTitle.textAttributes
}

// 恢复原始记录
Expand All @@ -220,9 +212,7 @@ private extension EachNavigationBar {
private extension EachNavigationItem {

func apply(_ configuration: UINavigationController.Configuration) {
if #available(iOS 11.0, *) {
largeTitleDisplayMode = configuration.largeTitle.displayMode
}
largeTitleDisplayMode = configuration.largeTitle.displayMode

// 清空修改记录
changed.removeAll()
Expand All @@ -231,10 +221,8 @@ private extension EachNavigationItem {
func update(_ configuration: UINavigationController.Configuration) {
let original = changed

if #available(iOS 11.0, *) {
if !changed.contains(\.largeTitleDisplayMode) {
largeTitleDisplayMode = configuration.largeTitle.displayMode
}
if !changed.contains(\.largeTitleDisplayMode) {
largeTitleDisplayMode = configuration.largeTitle.displayMode
}

// 恢复原始记录
Expand Down
4 changes: 2 additions & 2 deletions Example/EachNavigationBar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = 8G74YECJ4Z;
INFOPLIST_FILE = EachNavigationBar/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -507,7 +507,7 @@
CLANG_ENABLE_MODULES = YES;
DEVELOPMENT_TEAM = 8G74YECJ4Z;
INFOPLIST_FILE = EachNavigationBar/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
4 changes: 3 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
platform :ios, '10.0'
source "https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git"

platform :ios, '11.0'
use_frameworks!
install! 'cocoapods', :disable_input_output_paths => true

Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- EachNavigationBar (1.15.2)
- EachNavigationBar (1.15.3)

DEPENDENCIES:
- EachNavigationBar (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
EachNavigationBar: 6cdd53f13bf343fc1a4d0e7b7c7355ece7e4e1f3
EachNavigationBar: caedb0f99ce0e3e2de85f72e26fda5b3b237a539

PODFILE CHECKSUM: 3d71b1022ea23b1310df8ab078b9afba8a68e3d2
PODFILE CHECKSUM: 3503b3c3ed8084d02f4e01da33c319181282b40d

COCOAPODS: 1.11.2
6 changes: 3 additions & 3 deletions Example/Pods/Local Podspecs/EachNavigationBar.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d5900bd

Please sign in to comment.