three layer fixes
This commit is contained in:
parent
07b02963a6
commit
79b3b9b0c5
@ -35,21 +35,20 @@ open class ProgrammaticScrollViewController: ScrollingViewController {
|
||||
view.addSubview(scrollView)
|
||||
|
||||
// Sets the constraints for the scroll view
|
||||
let constraints = NSLayoutConstraint.constraintPinSubview(toSuperview: scrollView)
|
||||
topConstraint = constraints?[ConstraintTop] as? NSLayoutConstraint
|
||||
bottomConstraint = constraints?[ConstraintBot] as? NSLayoutConstraint
|
||||
scrollView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
|
||||
view.rightAnchor.constraint(equalTo: scrollView.rightAnchor).isActive = true
|
||||
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
|
||||
let contentView = MVMCoreUICommonViewsUtility.commonView()
|
||||
scrollView.addSubview(contentView)
|
||||
contentView.leftAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.leftAnchor).isActive = true
|
||||
scrollView.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true
|
||||
contentView.topAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.topAnchor).isActive = true
|
||||
scrollView.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
|
||||
|
||||
// Super will set later.
|
||||
contentWidthConstraint = contentView.widthAnchor.constraint(equalToConstant: 320.0)
|
||||
contentWidthConstraint?.isActive = true
|
||||
contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
|
||||
scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
|
||||
|
||||
self.contentView = contentView
|
||||
self.scrollView = scrollView
|
||||
|
||||
@ -12,7 +12,6 @@ open class ScrollingViewController: ViewController {
|
||||
public var dismissKeyboardTapGesture: UITapGestureRecognizer?
|
||||
@IBOutlet public var scrollView: UIScrollView!
|
||||
public var contentView: UIView?
|
||||
public var contentWidthConstraint: NSLayoutConstraint?
|
||||
|
||||
private var keyboardNotificationsAdded = false
|
||||
private var keyboardIsShowing = false
|
||||
@ -42,13 +41,7 @@ open class ScrollingViewController: ViewController {
|
||||
scrollView.alwaysBounceVertical = false
|
||||
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() {
|
||||
super.viewDidLayoutSubviews()
|
||||
view.setNeedsUpdateConstraints()
|
||||
|
||||
@ -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() {
|
||||
super.loadView()
|
||||
// The height is used to keep the bottom view at the bottom.
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -78,6 +64,7 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController {
|
||||
}
|
||||
|
||||
// Reset constraints
|
||||
topConstraint?.isActive = true
|
||||
bottomConstraint?.isActive = true
|
||||
heightConstraint?.isActive = false
|
||||
|
||||
@ -113,13 +100,9 @@ open class ThreeLayerViewController: ProgrammaticScrollViewController {
|
||||
|
||||
//MARK:-Setup
|
||||
extension ThreeLayerViewController {
|
||||
func setupViewAsTop() -> UIView? {
|
||||
if let topView = viewForTop() {
|
||||
self.topView = topView
|
||||
} else {
|
||||
topView = MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
}
|
||||
guard var topView = topView else { return nil }
|
||||
func setupViewAsTop() -> UIView {
|
||||
var topView = viewForTop() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
self.topView = topView
|
||||
|
||||
// Adds the top view outside the scroll if directed.
|
||||
if topViewOutsideOfScroll {
|
||||
@ -136,13 +119,11 @@ extension ThreeLayerViewController {
|
||||
return topView
|
||||
}
|
||||
|
||||
func setupViewAsMiddle() -> UIView? {
|
||||
if let middleView = viewForMiddle() {
|
||||
self.middleView = middleView
|
||||
} else {
|
||||
middleView = MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
}
|
||||
guard let middleView = middleView, let contentView = contentView else { return nil }
|
||||
func setupViewAsMiddle() -> UIView {
|
||||
let middleView = viewForMiddle() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
self.middleView = middleView
|
||||
|
||||
guard let contentView = contentView else { return middleView }
|
||||
contentView.addSubview(middleView)
|
||||
NSLayoutConstraint.pinViewLeft(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
|
||||
}
|
||||
|
||||
func setupViewAsBottom() -> UIView? {
|
||||
if let bottomView = viewForBottom() {
|
||||
self.bottomView = bottomView
|
||||
} else {
|
||||
bottomView = MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
}
|
||||
guard var bottomView = bottomView else { return nil }
|
||||
func setupViewAsBottom() -> UIView {
|
||||
var bottomView = viewForBottom() ?? MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
self.bottomView = bottomView
|
||||
|
||||
// Adds the bottom view outside the scroll if directed.
|
||||
if bottomViewOutsideOfScroll {
|
||||
bottomConstraint?.isActive = false;
|
||||
bottomConstraint?.isActive = false
|
||||
addViewOutsideOfScrollViewBottom(bottomView)
|
||||
|
||||
// Adds and returns an empty view to use for the internal logic.
|
||||
bottomView = MVMCoreUICommonViewsUtility.getView(with: 0)
|
||||
addViewInsideOfScrollViewBottom(bottomView)
|
||||
} else {
|
||||
bottomConstraint?.isActive = true;
|
||||
bottomConstraint?.isActive = true
|
||||
addViewInsideOfScrollViewBottom(bottomView)
|
||||
}
|
||||
return bottomView
|
||||
}
|
||||
|
||||
func setupLayers() {
|
||||
guard let contentView = contentView, let topView = setupViewAsTop(), let middleView = setupViewAsMiddle(), let bottomView = setupViewAsBottom() else {
|
||||
return
|
||||
}
|
||||
guard let contentView = contentView else { return }
|
||||
let topView = setupViewAsTop()
|
||||
let middleView = setupViewAsMiddle()
|
||||
let bottomView = setupViewAsBottom()
|
||||
let spaceAbove = spaceBetweenTopAndMiddle()
|
||||
let spaceBelow = spaceBetweenMiddleAndBottom()
|
||||
if let spaceAbove = spaceAbove, let spaceBelow = spaceBelow {
|
||||
@ -202,7 +180,7 @@ extension ThreeLayerViewController {
|
||||
contentView.addSubview(topSpacer)
|
||||
topSpacer.leftAnchor.constraint(equalTo: contentView.leftAnchor).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
|
||||
middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).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
|
||||
contentView.rightAnchor.constraint(equalTo: bottomSpacer.rightAnchor).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
|
||||
middleView.topAnchor.constraint(equalTo: topSpacer.bottomAnchor).isActive = true
|
||||
bottomSpacer.topAnchor.constraint(equalTo: middleView.bottomAnchor).isActive = true
|
||||
@ -236,7 +214,7 @@ extension ThreeLayerViewController {
|
||||
|
||||
func addViewOutsideOfScrollViewTop(_ view: UIView) {
|
||||
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
|
||||
NSLayoutConstraint.pinViewLeft(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) {
|
||||
guard let contentView = contentView else {
|
||||
return
|
||||
}
|
||||
guard let contentView = contentView else { return }
|
||||
contentView.addSubview(view);
|
||||
NSLayoutConstraint.pinViewLeft(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) {
|
||||
self.view?.addSubview(view)
|
||||
if let scrollView = scrollView, let parentView = self.view {
|
||||
view.topAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
|
||||
NSLayoutConstraint.pinViewLeft(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
|
||||
}
|
||||
guard let scrollView = scrollView, let parentView = self.view else { return }
|
||||
parentView.addSubview(view)
|
||||
view.topAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true
|
||||
NSLayoutConstraint.pinViewLeft(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
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +64,8 @@ import UIKit
|
||||
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
|
||||
navigationController.topViewController == viewController {
|
||||
// Update Panels
|
||||
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: viewController)
|
||||
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton ?? false, for: viewController)
|
||||
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton , for: viewController)
|
||||
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton , for: viewController)
|
||||
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user