Commit 341a3dc1 by Daniel Dahan

Fixed iOS 11 layout issues for NavigationController.

parent 4d5f53a3
## 2.12.11 ## 2.12.11
* Fixed iPhoneX topLayoutGuide constraints not properly being set for StatusBarController types. * Fixed iPhoneX topLayoutGuide constraints not properly being set for StatusBarController types.
* Fixed iOS 11 layout issues for NavigationController.
* [pr-945](https://github.com/CosmicMind/Material/pull/945): iPhoneX update for TabBar bottom line alignment. * [pr-945](https://github.com/CosmicMind/Material/pull/945): iPhoneX update for TabBar bottom line alignment.
## 2.12.10 ## 2.12.10
......
...@@ -266,19 +266,18 @@ public struct Grid { ...@@ -266,19 +266,18 @@ public struct Grid {
} }
} }
/// A memory reference to the Grid instance for UIView extensions. fileprivate var AssociatedInstanceKey: UInt8 = 0
fileprivate var GridKey: UInt8 = 0
extension UIView { extension UIView {
/// Grid reference. /// Grid reference.
public var grid: Grid { public var grid: Grid {
get { get {
return AssociatedObject.get(base: self, key: &GridKey) { return AssociatedObject.get(base: self, key: &AssociatedInstanceKey) {
return Grid(context: self) return Grid(context: self)
} }
} }
set(value) { set(value) {
AssociatedObject.set(base: self, key: &GridKey, value: value) AssociatedObject.set(base: self, key: &AssociatedInstanceKey, value: value)
} }
} }
......
...@@ -36,6 +36,12 @@ open class NavigationBar: UINavigationBar { ...@@ -36,6 +36,12 @@ open class NavigationBar: UINavigationBar {
return 0 < bounds.width && 0 < bounds.height && nil != superview return 0 < bounds.width && 0 < bounds.height && nil != superview
} }
/// Detail UILabel when in landscape for iOS 11.
fileprivate var toolbarToText: [Toolbar: String?]?
/// PulseAnimation for different views.
fileprivate var viewToPulseAnimation: [UIView: PulseAnimation]?
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
return CGSize(width: bounds.width, height: bounds.height) return CGSize(width: bounds.width, height: bounds.height)
} }
...@@ -154,9 +160,14 @@ open class NavigationBar: UINavigationBar { ...@@ -154,9 +160,14 @@ open class NavigationBar: UINavigationBar {
isTranslucent = false isTranslucent = false
depthPreset = .depth1 depthPreset = .depth1
contentScaleFactor = Screen.scale contentScaleFactor = Screen.scale
backButtonImage = Icon.cm.arrowBack
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
backButtonImage = Icon.cm.arrowBack
if #available(iOS 11, *) {
toolbarToText = [:]
viewToPulseAnimation = [:]
}
let image = UIImage() let image = UIImage()
shadowImage = image shadowImage = image
...@@ -175,35 +186,51 @@ internal extension NavigationBar { ...@@ -175,35 +186,51 @@ internal extension NavigationBar {
return return
} }
item.toolbar.backgroundColor = .clear let toolbar = item.toolbar
item.titleView = item.toolbar toolbar.backgroundColor = .clear
toolbar.interimSpace = interimSpace
toolbar.contentEdgeInsets = contentEdgeInsets
guard let v = item.titleView as? Toolbar else { if #available(iOS 11, *) {
return if Application.shouldStatusBarBeHidden {
toolbar.contentEdgeInsetsPreset = .none
for v in toolbar.leftViews + toolbar.rightViews {
guard var b = v as? Pulseable else {
continue
} }
if #available(iOS 11.0, *) { guard .none != b.pulseAnimation else {
let h = CGFloat(heightPreset.rawValue) continue
frame = CGRect(x: frame.origin.x, y: 20, width: frame.size.width, height: h) }
for subview in subviews { viewToPulseAnimation?[v] = b.pulseAnimation
var stringFromClass = NSStringFromClass(subview.classForCoder) b.pulseAnimation = .none
if stringFromClass.contains("BarBackground") {
subview.frame = CGRect(x: 0, y: 0, width: frame.width, height: h)
} }
stringFromClass = NSStringFromClass(subview.classForCoder) if nil != toolbar.detailLabel.text {
if stringFromClass.contains("BarContent") { toolbarToText?[toolbar] = toolbar.detailLabel.text
subview.frame = CGRect(x: subview.frame.origin.x, y: 0, width: subview.frame.width, height: h) toolbar.detailLabel.text = nil
} }
} else if nil != toolbarToText?[toolbar] {
toolbar.detailLabel.text = toolbarToText?[toolbar] ?? nil
toolbarToText?[toolbar] = nil
for v in toolbar.leftViews + toolbar.rightViews {
guard var b = v as? Pulseable else {
continue
} }
v.frame = frame guard let a = viewToPulseAnimation?[v] else {
} else { continue
v.frame = bounds }
b.pulseAnimation = a
}
}
} }
v.contentEdgeInsets = contentEdgeInsets item.titleView = toolbar
v.interimSpace = interimSpace item.titleView!.frame = frame
} }
} }
...@@ -158,12 +158,12 @@ extension NavigationController: UINavigationBarDelegate { ...@@ -158,12 +158,12 @@ extension NavigationController: UINavigationBarDelegate {
item.backButton.image = v.backButtonImage item.backButton.image = v.backButtonImage
} }
item.backButton.addTarget(self, action: #selector(handle(backButton:)), for: .touchUpInside)
if !item.backButton.isHidden { if !item.backButton.isHidden {
item.leftViews.insert(item.backButton, at: 0) item.leftViews.insert(item.backButton, at: 0)
} }
item.backButton.addTarget(self, action: #selector(handle(backButton:)), for: .touchUpInside)
item.hidesBackButton = false item.hidesBackButton = false
item.setHidesBackButton(true, animated: false) item.setHidesBackButton(true, animated: false)
......
...@@ -120,8 +120,8 @@ public struct Pulse { ...@@ -120,8 +120,8 @@ public struct Pulse {
let w = view.bounds.width let w = view.bounds.width
let h = view.bounds.height let h = view.bounds.height
Motion.disable({ [ Motion.disable { [
n = .center == animation ? w < h ? w : h : w < h ? h : w, n = w < h ? w : h,
bounds = layer.bounds, bounds = layer.bounds,
animation = animation, animation = animation,
color = color, color = color,
...@@ -141,7 +141,7 @@ public struct Pulse { ...@@ -141,7 +141,7 @@ public struct Pulse {
pLayer.cornerRadius = n / 2 pLayer.cornerRadius = n / 2
pLayer.backgroundColor = color.withAlphaComponent(opacity).cgColor pLayer.backgroundColor = color.withAlphaComponent(opacity).cgColor
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 0, y: 0)) pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 0, y: 0))
}) }
bLayer.setValue(false, forKey: "animated") bLayer.setValue(false, forKey: "animated")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment