three layer fixes

This commit is contained in:
Pfeil, Scott Robert 2020-04-22 20:44:37 -04:00
parent 07b02963a6
commit 79b3b9b0c5
4 changed files with 40 additions and 73 deletions

View File

@ -35,21 +35,20 @@ open class ProgrammaticScrollViewController: ScrollingViewController {
view.addSubview(scrollView) view.addSubview(scrollView)
// Sets the constraints for the scroll view // Sets the constraints for the scroll view
let constraints = NSLayoutConstraint.constraintPinSubview(toSuperview: scrollView) scrollView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
topConstraint = constraints?[ConstraintTop] as? NSLayoutConstraint view.rightAnchor.constraint(equalTo: scrollView.rightAnchor).isActive = true
bottomConstraint = constraints?[ConstraintBot] as? NSLayoutConstraint topConstraint = scrollView.topAnchor.constraint(equalTo: view.topAnchor)
topConstraint?.isActive = true
bottomConstraint = view.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor)
bottomConstraint?.isActive = true
// Sets the constraints for the content view // Sets the constraints for the content view
let contentView = MVMCoreUICommonViewsUtility.commonView() let contentView = MVMCoreUICommonViewsUtility.commonView()
scrollView.addSubview(contentView) scrollView.addSubview(contentView)
contentView.leftAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.leftAnchor).isActive = true contentView.leftAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.leftAnchor).isActive = true
scrollView.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true scrollView.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true
contentView.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor).isActive = true contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
scrollView.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
// Super will set later.
contentWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: 320.0)
contentWidthConstraint?.isActive = true
self.contentView = contentView self.contentView = contentView
self.scrollView = scrollView self.scrollView = scrollView

View File

@ -12,7 +12,6 @@ open class ScrollingViewController: ViewController {
public var dismissKeyboardTapGesture: UITapGestureRecognizer? public var dismissKeyboardTapGesture: UITapGestureRecognizer?
@IBOutlet public var scrollView: UIScrollView! @IBOutlet public var scrollView: UIScrollView!
public var contentView: UIView? public var contentView: UIView?
public var contentWidthConstraint: NSLayoutConstraint?
private var keyboardNotificationsAdded = false private var keyboardNotificationsAdded = false
private var keyboardIsShowing = false private var keyboardIsShowing = false
@ -42,13 +41,7 @@ open class ScrollingViewController: ViewController {
scrollView.alwaysBounceVertical = false scrollView.alwaysBounceVertical = false
scrollView.delegate = self scrollView.delegate = self
} }
open override func updateViewConstraints() {
// Sets the width of the content to the width of the screen.
contentWidthConstraint?.constant = view.bounds.width - scrollView.contentInset.left - scrollView.contentInset.right
super.updateViewConstraints()
}
open override func viewDidLayoutSubviews() { open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews() super.viewDidLayoutSubviews()
view.setNeedsUpdateConstraints() view.setNeedsUpdateConstraints()

View File

@ -41,25 +41,11 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController {
} }
} }
open override func updateViewConstraints() {
guard let scrollView = scrollView else {
super.updateViewConstraints()
return
}
if scrollView.contentInsetAdjustmentBehavior == UIScrollView.ContentInsetAdjustmentBehavior.automatic {
heightConstraint?.constant = -scrollView.adjustedContentInset.top - scrollView.adjustedContentInset.bottom
} else {
heightConstraint?.constant = -scrollView.contentInset.top - scrollView.contentInset.bottom
}
super.updateViewConstraints()
}
open override func loadView() { open override func loadView() {
super.loadView() super.loadView()
// The height is used to keep the bottom view at the bottom. // The height is used to keep the bottom view at the bottom.
if let contentView = contentView, let scrollView = scrollView { if let contentView = contentView, let scrollView = scrollView {
heightConstraint = contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor, multiplier: 1.0) heightConstraint = contentView.heightAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.heightAnchor, multiplier: 1.0)
heightConstraint?.priority = UILayoutPriority.defaultLow heightConstraint?.priority = UILayoutPriority.defaultLow
} }
} }
@ -78,6 +64,7 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController {
} }
// Reset constraints // Reset constraints
topConstraint?.isActive = true
bottomConstraint?.isActive = true bottomConstraint?.isActive = true
heightConstraint?.isActive = false heightConstraint?.isActive = false
@ -113,13 +100,9 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController {
//MARK:-Setup //MARK:-Setup
extension ThreeLayerViewController { extension ThreeLayerViewController {
func setupViewAsTop() -> UIView? { func setupViewAsTop() -> UIView {
if let topView = viewForTop() { var topView = viewForTop() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
self.topView = topView self.topView = topView
} else {
topView = MVMCoreUICommonViewsUtility.getView(with: 0)
}
guard var topView = topView else { return nil }
// Adds the top view outside the scroll if directed. // Adds the top view outside the scroll if directed.
if topViewOutsideOfScroll { if topViewOutsideOfScroll {
@ -136,13 +119,11 @@ extension ThreeLayerViewController {
return topView return topView
} }
func setupViewAsMiddle() -> UIView? { func setupViewAsMiddle() -> UIView {
if let middleView = viewForMiddle() { let middleView = viewForMiddle() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
self.middleView = middleView self.middleView = middleView
} else {
middleView = MVMCoreUICommonViewsUtility.getView(with: 0) guard let contentView = contentView else { return middleView }
}
guard let middleView = middleView, let contentView = contentView else { return nil }
contentView.addSubview(middleView) contentView.addSubview(middleView)
NSLayoutConstraint.pinViewLeft(toSuperview: middleView, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: middleView, useMargins: useMargins, constant: 0).isActive = true
NSLayoutConstraint.pinViewRight(toSuperview: middleView, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewRight(toSuperview: middleView, useMargins: useMargins, constant: 0).isActive = true
@ -150,33 +131,30 @@ extension ThreeLayerViewController {
return middleView return middleView
} }
func setupViewAsBottom() -> UIView? { func setupViewAsBottom() -> UIView {
if let bottomView = viewForBottom() { var bottomView = viewForBottom() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
self.bottomView = bottomView self.bottomView = bottomView
} else {
bottomView = MVMCoreUICommonViewsUtility.getView(with: 0)
}
guard var bottomView = bottomView else { return nil }
// Adds the bottom view outside the scroll if directed. // Adds the bottom view outside the scroll if directed.
if bottomViewOutsideOfScroll { if bottomViewOutsideOfScroll {
bottomConstraint?.isActive = false; bottomConstraint?.isActive = false
addViewOutsideOfScrollViewBottom(bottomView) addViewOutsideOfScrollViewBottom(bottomView)
// Adds and returns an empty view to use for the internal logic. // Adds and returns an empty view to use for the internal logic.
bottomView = MVMCoreUICommonViewsUtility.getView(with: 0) bottomView = MVMCoreUICommonViewsUtility.getView(with: 0)
addViewInsideOfScrollViewBottom(bottomView) addViewInsideOfScrollViewBottom(bottomView)
} else { } else {
bottomConstraint?.isActive = true; bottomConstraint?.isActive = true
addViewInsideOfScrollViewBottom(bottomView) addViewInsideOfScrollViewBottom(bottomView)
} }
return bottomView return bottomView
} }
func setupLayers() { func setupLayers() {
guard let contentView = contentView, let topView = setupViewAsTop(), let middleView = setupViewAsMiddle(), let bottomView = setupViewAsBottom() else { guard let contentView = contentView else { return }
return let topView = setupViewAsTop()
} let middleView = setupViewAsMiddle()
let bottomView = setupViewAsBottom()
let spaceAbove = spaceBetweenTopAndMiddle() let spaceAbove = spaceBetweenTopAndMiddle()
let spaceBelow = spaceBetweenMiddleAndBottom() let spaceBelow = spaceBetweenMiddleAndBottom()
if let spaceAbove = spaceAbove, let spaceBelow = spaceBelow { if let spaceAbove = spaceAbove, let spaceBelow = spaceBelow {
@ -202,7 +180,7 @@ extension ThreeLayerViewController {
contentView.addSubview(topSpacer) contentView.addSubview(topSpacer)
topSpacer.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true topSpacer.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true
contentView.rightAnchor.constraint(equalTo: topSpacer.rightAnchor).isActive = true contentView.rightAnchor.constraint(equalTo: topSpacer.rightAnchor).isActive = true
topSpacer.heightAnchor.constraint(greaterThanOrEqualToConstant: PaddingTwo).isActive = true topSpacer.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
topSpacer.topAnchor.constraint(equalTo: topView.bottomAnchor).isActive = true topSpacer.topAnchor.constraint(equalTo: topView.bottomAnchor).isActive = true
middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).isActive = true middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).isActive = true
bottomView.topAnchor.constraint(equalTo: middleView.bottomAnchor, constant: spaceBelow).isActive = true bottomView.topAnchor.constraint(equalTo: middleView.bottomAnchor, constant: spaceBelow).isActive = true
@ -217,7 +195,7 @@ extension ThreeLayerViewController {
bottomSpacer.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true bottomSpacer.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true
contentView.rightAnchor.constraint(equalTo: bottomSpacer.rightAnchor).isActive = true contentView.rightAnchor.constraint(equalTo: bottomSpacer.rightAnchor).isActive = true
topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor).isActive = true topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor).isActive = true
topSpacer.heightAnchor.constraint(greaterThanOrEqualToConstant: PaddingTwo).isActive = true topSpacer.heightAnchor.constraint(greaterThanOrEqualToConstant: 0).isActive = true
topSpacer.topAnchor.constraint(equalTo: topView.bottomAnchor).isActive = true topSpacer.topAnchor.constraint(equalTo: topView.bottomAnchor).isActive = true
middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).isActive = true middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).isActive = true
bottomSpacer.topAnchor.constraint(equalTo: middleView.bottomAnchor).isActive = true bottomSpacer.topAnchor.constraint(equalTo: middleView.bottomAnchor).isActive = true
@ -236,7 +214,7 @@ extension ThreeLayerViewController {
func addViewOutsideOfScrollViewTop(_ view: UIView) { func addViewOutsideOfScrollViewTop(_ view: UIView) {
guard let scrollView = scrollView, let parentView = self.view else { return } guard let scrollView = scrollView, let parentView = self.view else { return }
self.view?.addSubview(view) parentView.addSubview(view)
scrollView.topAnchor.constraint(equalTo: view.bottomAnchor).isActive = true scrollView.topAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
@ -244,9 +222,7 @@ extension ThreeLayerViewController {
} }
func addViewInsideOfScrollViewBottom(_ view: UIView) { func addViewInsideOfScrollViewBottom(_ view: UIView) {
guard let contentView = contentView else { guard let contentView = contentView else { return }
return
}
contentView.addSubview(view); contentView.addSubview(view);
NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
@ -254,12 +230,11 @@ extension ThreeLayerViewController {
} }
func addViewOutsideOfScrollViewBottom(_ view: UIView) { func addViewOutsideOfScrollViewBottom(_ view: UIView) {
self.view?.addSubview(view) guard let scrollView = scrollView, let parentView = self.view else { return }
if let scrollView = scrollView, let parentView = self.view { parentView.addSubview(view)
view.topAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true view.topAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true NSLayoutConstraint.pinViewRight(toSuperview: view, useMargins: useMargins, constant: 0).isActive = true
parentView.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true parentView.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
} }
} }

View File

@ -64,8 +64,8 @@ import UIKit
if navigationController == MVMCoreUISplitViewController.main()?.navigationController, if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
navigationController.topViewController == viewController { navigationController.topViewController == viewController {
// Update Panels // Update Panels
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: viewController) MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton , for: viewController)
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton ?? false, for: viewController) MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton , for: viewController)
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint) MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
} }
} }