Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
huangboju committed Mar 16, 2017
1 parent 0e98209 commit 437f5ea
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions ETNavBarTransparent/ETNavBarTransparent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension UINavigationController {
let nowColor = averageColor(fromColor: fromColor, toColor: toColor, percent: percentComplete)
navigationBar.tintColor = nowColor
}

//Calculate the middle Color with translation percent
private func averageColor(fromColor:UIColor, toColor:UIColor, percent:CGFloat) -> UIColor {
var fromRed: CGFloat = 0.0
Expand Down Expand Up @@ -113,43 +113,38 @@ extension UINavigationController {
navigationBar.tintColor = viewController.navBarTintColor
return et_popToViewController(viewController, animated: animated)
}

func et_popToRootViewController(animated: Bool) -> [UIViewController]? {
setNeedsNavigationBackground(alpha: viewControllers.first?.navBarBgAlpha ?? 0)
navigationBar.tintColor = viewControllers.first?.navBarTintColor
return et_popToRootViewController(animated: animated)
}

fileprivate func setNeedsNavigationBackground(alpha:CGFloat) {
fileprivate func setNeedsNavigationBackground(alpha: CGFloat) {

let barBackgroundView = navigationBar.subviews[0]
if let shadowView = barBackgroundView.value(forKey: "_shadowView") as? UIView {

let valueForKey = barBackgroundView.value(forKey:)

if let shadowView = valueForKey("_shadowView") as? UIView {
shadowView.alpha = alpha
}

if navigationBar.isTranslucent {
if #available(iOS 10.0, *){
guard navigationBar.backgroundImage(for: .default) == nil else {
return
}

if let backgroundEffectView = barBackgroundView.value(forKey: "_backgroundEffectView") as? UIView {
if #available(iOS 10.0, *) {
if let backgroundEffectView = valueForKey("_backgroundEffectView") as? UIView, navigationBar.backgroundImage(for: .default) == nil {
backgroundEffectView.alpha = alpha
return
}

}else{
guard let adaptiveBackdrop = barBackgroundView.value(forKey: "_adaptiveBackdrop") as? UIView else {
return
}

if let backdropEffectView = adaptiveBackdrop.value(forKey: "_backdropEffectView") as? UIView {

} else {
if let adaptiveBackdrop = valueForKey("_adaptiveBackdrop") as? UIView , let backdropEffectView = adaptiveBackdrop.value(forKey: "_backdropEffectView") as? UIView {
backdropEffectView.alpha = alpha
return
}
}
}

barBackgroundView.alpha = alpha
}
}
Expand Down Expand Up @@ -179,7 +174,7 @@ extension UINavigationController: UINavigationControllerDelegate,UINavigationBar

self.navigationBar.tintColor = context.viewController(forKey: $0)?.navBarTintColor
}

if context.isCancelled {
let cancellDuration: TimeInterval = context.transitionDuration * Double(context.percentComplete)
UIView.animate(withDuration: cancellDuration, animations: {
Expand Down Expand Up @@ -223,24 +218,17 @@ extension UIViewController {

open var navBarBgAlpha: CGFloat {
get {

guard let alpha = objc_getAssociatedObject(self, &AssociatedKeys.navBarBgAlpha) as? CGFloat else {
return 1.0
}
return alpha

}
set {
var alpha = newValue
if alpha > 1 {
alpha = 1
}
if alpha < 0 {
alpha = 0
}

let alpha = max(min(newValue, 1), 0) // 必须在 0~1的范围

objc_setAssociatedObject(self, &AssociatedKeys.navBarBgAlpha, alpha, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

//Update UI
navigationController?.setNeedsNavigationBackground(alpha: alpha)
}
Expand Down

0 comments on commit 437f5ea

Please sign in to comment.