From 2424176131a1cf4dbb6062ac0a54c30574824664 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 13 Aug 2019 09:14:56 -0400 Subject: [PATCH] Calculation of size fix --- .../ThreeLayerTableViewController.swift | 21 ++++++++++--------- MVMCoreUI/Utility/MVMCoreUIUtility.h | 3 ++- MVMCoreUI/Utility/MVMCoreUIUtility.m | 11 ++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift index 51a936b0..9d3052a0 100644 --- a/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift +++ b/MVMCoreUI/BaseControllers/ThreeLayerTableViewController.swift @@ -28,11 +28,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { MFStyler.setDefaultMarginsFor(contentView, size: width) if let topView = topView as? MVMCoreViewProtocol { topView.updateView(width) - showHeader() + showHeader(width) } if let bottomView = bottomView as? MVMCoreViewProtocol { bottomView.updateView(width) - showFooter() + showFooter(width) } self.tableView?.reloadData() } @@ -102,14 +102,15 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { currentSpaceForCompare = currentSpace * 2; } + let width = view.bounds.width if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 0.1) { if fillTop && fillBottom { // space both let half = newSpace / 2 topViewBottomConstraint?.constant = half bottomViewTopConstraint?.constant = half - showHeader() - showFooter() + showHeader(width) + showFooter(width) } else if fillTop { // Only top is spaced (half the size if the bottom view is out of the scroll because it needs to be sized as if there are two spacers but there is only one. if bottomViewOutsideOfScrollArea { @@ -117,11 +118,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { } else { topViewBottomConstraint?.constant = newSpace } - showHeader() + showHeader(width) } else if fillBottom { // Only bottom is spaced. bottomViewTopConstraint?.constant = newSpace - showFooter() + showFooter(width) } } } @@ -140,7 +141,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { topViewBottomConstraint = headerView.bottomAnchor.constraint(equalTo: topView.bottomAnchor, constant: spaceBelowTopView() ?? 0) topViewBottomConstraint?.isActive = true self.headerView = headerView - showHeader() + showHeader(nil) } /// Gets the bottom view and adds it to a spacing view, footerView, and then calls showFooter. @@ -156,11 +157,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { footerView.rightAnchor.constraint(equalTo: bottomView.rightAnchor).isActive = true footerView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor).isActive = true self.footerView = footerView - showFooter() + showFooter(nil) } /// Takes the current headerView and adds it to the tableHeaderView - func showHeader() { + func showHeader(_ sizingWidth: CGFloat?) { headerView?.removeFromSuperview() tableView?.tableHeaderView = nil guard let headerView = headerView else { @@ -176,7 +177,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController { } /// Takes the current footerView and adds it to the tableFooterView - func showFooter() { + func showFooter(_ sizingWidth: CGFloat?) { footerView?.removeFromSuperview() safeAreaView?.removeFromSuperview() guard let footerView = footerView, let tableView = tableView else { diff --git a/MVMCoreUI/Utility/MVMCoreUIUtility.h b/MVMCoreUI/Utility/MVMCoreUIUtility.h index b6698537..9300de90 100644 --- a/MVMCoreUI/Utility/MVMCoreUIUtility.h +++ b/MVMCoreUI/Utility/MVMCoreUIUtility.h @@ -71,8 +71,9 @@ NS_ASSUME_NONNULL_BEGIN // Gets the constraint height to be whatever space is left in the scroll view. + (CGFloat)getVariableConstraintHeight:(CGFloat)currentConstant inScrollView:(nonnull UIScrollView *)scrollView minimumHeight:(CGFloat)minimumHeight; -// Sets the view's frame according to constraint. +/// Sets the view's frame according to constraints. + (void)sizeViewToFit:(nullable UIView *)view; ++ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width; #pragma mark - Keyboard diff --git a/MVMCoreUI/Utility/MVMCoreUIUtility.m b/MVMCoreUI/Utility/MVMCoreUIUtility.m index 8201e999..e8523a61 100644 --- a/MVMCoreUI/Utility/MVMCoreUIUtility.m +++ b/MVMCoreUI/Utility/MVMCoreUIUtility.m @@ -119,7 +119,7 @@ #pragma mark - Sizing + (CGFloat)getWidth { - UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController ?: [UIApplication sharedApplication].keyWindow.rootViewController; + UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController; if (controller) { return CGRectGetWidth(controller.view.bounds); } else { @@ -138,7 +138,7 @@ } + (CGFloat)getHeightOfView:(nonnull UIView *)view forWidth:(nullable NSNumber *)width { - CGFloat floatWidth = (width ? width.floatValue : CGRectGetWidth([MVMCoreNavigationHandler sharedNavigationHandler].navigationController.view.bounds)); + CGFloat floatWidth = (width ? width.floatValue : [MVMCoreUIUtility getWidth]); return [view systemLayoutSizeFittingSize:CGSizeMake(floatWidth, UILayoutFittingCompressedSize.height) withHorizontalFittingPriority:1000 verticalFittingPriority:250].height; } @@ -192,6 +192,13 @@ view.frame = frame; } ++ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width { + CGFloat height = [MVMCoreUIUtility getHeightOfView:view forWidth:width]; + CGRect frame = view.frame; + frame.size.height = height; + view.frame = frame; +} + #pragma mark - Keyboard + (void)setScrollViewInsetForKeyboardShow:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController rectToScrollTo:(nonnull CGRect (^)(void))rectToScrollTo {