Commit 341a3dc1 by Daniel Dahan

Fixed iOS 11 layout issues for NavigationController.

parent 4d5f53a3
## 2.12.11
* 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.
## 2.12.10
......
......@@ -266,19 +266,18 @@ public struct Grid {
}
}
/// A memory reference to the Grid instance for UIView extensions.
fileprivate var GridKey: UInt8 = 0
fileprivate var AssociatedInstanceKey: UInt8 = 0
extension UIView {
/// Grid reference.
public var grid: Grid {
get {
return AssociatedObject.get(base: self, key: &GridKey) {
return AssociatedObject.get(base: self, key: &AssociatedInstanceKey) {
return Grid(context: self)
}
}
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 {
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 {
return CGSize(width: bounds.width, height: bounds.height)
}
......@@ -154,9 +160,14 @@ open class NavigationBar: UINavigationBar {
isTranslucent = false
depthPreset = .depth1
contentScaleFactor = Screen.scale
backButtonImage = Icon.cm.arrowBack
contentEdgeInsetsPreset = .square1
interimSpacePreset = .interimSpace3
backButtonImage = Icon.cm.arrowBack
if #available(iOS 11, *) {
toolbarToText = [:]
viewToPulseAnimation = [:]
}
let image = UIImage()
shadowImage = image
......@@ -175,35 +186,51 @@ internal extension NavigationBar {
return
}
item.toolbar.backgroundColor = .clear
item.titleView = item.toolbar
guard let v = item.titleView as? Toolbar else {
return
}
let toolbar = item.toolbar
toolbar.backgroundColor = .clear
toolbar.interimSpace = interimSpace
toolbar.contentEdgeInsets = contentEdgeInsets
if #available(iOS 11.0, *) {
let h = CGFloat(heightPreset.rawValue)
frame = CGRect(x: frame.origin.x, y: 20, width: frame.size.width, height: h)
if #available(iOS 11, *) {
if Application.shouldStatusBarBeHidden {
toolbar.contentEdgeInsetsPreset = .none
for subview in subviews {
var stringFromClass = NSStringFromClass(subview.classForCoder)
if stringFromClass.contains("BarBackground") {
subview.frame = CGRect(x: 0, y: 0, width: frame.width, height: h)
for v in toolbar.leftViews + toolbar.rightViews {
guard var b = v as? Pulseable else {
continue
}
guard .none != b.pulseAnimation else {
continue
}
viewToPulseAnimation?[v] = b.pulseAnimation
b.pulseAnimation = .none
}
stringFromClass = NSStringFromClass(subview.classForCoder)
if stringFromClass.contains("BarContent") {
subview.frame = CGRect(x: subview.frame.origin.x, y: 0, width: subview.frame.width, height: h)
if nil != toolbar.detailLabel.text {
toolbarToText?[toolbar] = toolbar.detailLabel.text
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
}
guard let a = viewToPulseAnimation?[v] else {
continue
}
b.pulseAnimation = a
}
}
v.frame = frame
} else {
v.frame = bounds
}
v.contentEdgeInsets = contentEdgeInsets
v.interimSpace = interimSpace
item.titleView = toolbar
item.titleView!.frame = frame
}
}
......@@ -158,12 +158,12 @@ extension NavigationController: UINavigationBarDelegate {
item.backButton.image = v.backButtonImage
}
item.backButton.addTarget(self, action: #selector(handle(backButton:)), for: .touchUpInside)
if !item.backButton.isHidden {
item.leftViews.insert(item.backButton, at: 0)
}
item.backButton.addTarget(self, action: #selector(handle(backButton:)), for: .touchUpInside)
item.hidesBackButton = false
item.setHidesBackButton(true, animated: false)
......
......@@ -120,8 +120,8 @@ public struct Pulse {
let w = view.bounds.width
let h = view.bounds.height
Motion.disable({ [
n = .center == animation ? w < h ? w : h : w < h ? h : w,
Motion.disable { [
n = w < h ? w : h,
bounds = layer.bounds,
animation = animation,
color = color,
......@@ -141,7 +141,7 @@ public struct Pulse {
pLayer.cornerRadius = n / 2
pLayer.backgroundColor = color.withAlphaComponent(opacity).cgColor
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: 0, y: 0))
})
}
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