Skip to content

Commit

Permalink
Update for iOS13
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderTan committed Jul 17, 2019
1 parent a921c85 commit 870ac82
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ETNavBarTransparent.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = 'ETNavBarTransparent'
s.version = '1.1.2'
s.version = '1.1.3'
s.license = 'MIT'
s.summary = 'Change NavigationBar‘s transparency at pop gestrue and other situation'
s.homepage = 'https://github.com/EnderTan/ETNavBarTransparent'
s.author = { 'Ender Tan' => '[email protected]' }
s.social_media_url = 'http://weibo.com/endertan'
s.source = { :git => 'https://github.com/EnderTan/ETNavBarTransparent.git', :tag => '1.1.2' }
s.source = { :git => 'https://github.com/EnderTan/ETNavBarTransparent.git', :tag => '1.1.3' }
s.platform = :ios, '8.0'
s.source_files = 'ETNavBarTransparent','ETNavBarTransparent/**/*'
s.requires_arc = true
Expand Down
46 changes: 41 additions & 5 deletions ETNavBarTransparent/ETNavBarTransparent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ extension UINavigationController {
DispatchQueue.once(token: onceToken) {
let needSwizzleSelectorArr = [
NSSelectorFromString("_updateInteractiveTransition:"),
#selector(popToViewController),
#selector(popToRootViewController)
#selector(popViewController(animated:)),
#selector(popToViewController(_:animated:)),
#selector(popToRootViewController(animated:))
]

for selector in needSwizzleSelectorArr {
Expand All @@ -75,6 +76,16 @@ extension UINavigationController {
return
}

if #available(iOS 10.0, *) {
coordinator.notifyWhenInteractionChanges({ (context) in
self.dealInteractionChanges(context)
})
} else {
coordinator.notifyWhenInteractionEnds({ (context) in
self.dealInteractionChanges(context)
})
}

let fromViewController = coordinator.viewController(forKey: .from)
let toViewController = coordinator.viewController(forKey: .to)

Expand Down Expand Up @@ -121,6 +132,17 @@ extension UINavigationController {
return et_popToViewController(viewController, animated: animated)
}

@objc func et_popViewControllerAnimated(_ animated: Bool) -> UIViewController? {
if #available(iOS 13.0, *) {
if (viewControllers.count > 1 && interactivePopGestureRecognizer?.state != .began){
let popToVC = viewControllers[viewControllers.count - 2]
setNeedsNavigationBackground(alpha: popToVC.navBarBgAlpha)
navigationBar.tintColor = popToVC.navBarTintColor
}
}
return et_popViewControllerAnimated(animated)
}

@objc func et_popToRootViewControllerAnimated(_ animated: Bool) -> [UIViewController]? {
setNeedsNavigationBackground(alpha: viewControllers.first?.navBarBgAlpha ?? 0)
navigationBar.tintColor = viewControllers.first?.navBarTintColor
Expand All @@ -129,7 +151,7 @@ extension UINavigationController {

fileprivate func setNeedsNavigationBackground(alpha: CGFloat) {
if let barBackgroundView = navigationBar.subviews.first {
let valueForKey = barBackgroundView.value(forKey:)
let valueForKey = barBackgroundView.getIvar(forKey:)

if let shadowView = valueForKey("_shadowView") as? UIView {
shadowView.alpha = alpha
Expand Down Expand Up @@ -157,6 +179,16 @@ extension UINavigationController {
}
}

extension NSObject {
func getIvar(forKey key: String) -> Any? {
guard let _var = class_getInstanceVariable(type(of: self), key) else {
return nil
}

return object_getIvar(self, _var)
}
}

extension UINavigationController: UINavigationBarDelegate {

public func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
Expand All @@ -176,8 +208,12 @@ extension UINavigationController: UINavigationBarDelegate {
let itemCount = navigationBar.items?.count ?? 0
let n = viewControllers.count >= itemCount ? 2 : 1
let popToVC = viewControllers[viewControllers.count - n]

popToViewController(popToVC, animated: true)
if #available(iOS 13.0, *) {
setNeedsNavigationBackground(alpha: popToVC.navBarBgAlpha)
navigationBar.tintColor = popToVC.navBarTintColor
} else {
popToViewController(popToVC, animated: true)
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
TargetAttributes = {
373664ED1E6E9BE000239537 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = NAC5X5LCW4;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
Expand All @@ -122,6 +121,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -279,7 +279,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = NAC5X5LCW4;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ETNavBarTransparentDemo",
Expand All @@ -298,7 +298,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = NAC5X5LCW4;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ETNavBarTransparentDemo",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "7AC55737-19BA-4A2A-9F5F-4CDE62EE5151"
type = "1"
version = "2.0">
</Bucket>

0 comments on commit 870ac82

Please sign in to comment.