Merge branch 'bugfix/size_calculation' into 'develop'

Calculation of size fix

See merge request BPHV_MIPS/mvm_core_ui!112
This commit is contained in:
Pfeil, Scott Robert 2019-08-13 09:35:04 -04:00
commit 18c916eba0
3 changed files with 22 additions and 13 deletions

View File

@ -28,11 +28,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
MFStyler.setDefaultMarginsFor(contentView, size: width) MFStyler.setDefaultMarginsFor(contentView, size: width)
if let topView = topView as? MVMCoreViewProtocol { if let topView = topView as? MVMCoreViewProtocol {
topView.updateView(width) topView.updateView(width)
showHeader() showHeader(width)
} }
if let bottomView = bottomView as? MVMCoreViewProtocol { if let bottomView = bottomView as? MVMCoreViewProtocol {
bottomView.updateView(width) bottomView.updateView(width)
showFooter() showFooter(width)
} }
self.tableView?.reloadData() self.tableView?.reloadData()
} }
@ -102,14 +102,15 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
currentSpaceForCompare = currentSpace * 2; currentSpaceForCompare = currentSpace * 2;
} }
let width = view.bounds.width
if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 0.1) { if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 0.1) {
if fillTop && fillBottom { if fillTop && fillBottom {
// space both // space both
let half = newSpace / 2 let half = newSpace / 2
topViewBottomConstraint?.constant = half topViewBottomConstraint?.constant = half
bottomViewTopConstraint?.constant = half bottomViewTopConstraint?.constant = half
showHeader() showHeader(width)
showFooter() showFooter(width)
} else if fillTop { } 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. // 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 { if bottomViewOutsideOfScrollArea {
@ -117,11 +118,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
} else { } else {
topViewBottomConstraint?.constant = newSpace topViewBottomConstraint?.constant = newSpace
} }
showHeader() showHeader(width)
} else if fillBottom { } else if fillBottom {
// Only bottom is spaced. // Only bottom is spaced.
bottomViewTopConstraint?.constant = newSpace 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 = headerView.bottomAnchor.constraint(equalTo: topView.bottomAnchor, constant: spaceBelowTopView() ?? 0)
topViewBottomConstraint?.isActive = true topViewBottomConstraint?.isActive = true
self.headerView = headerView self.headerView = headerView
showHeader() showHeader(nil)
} }
/// Gets the bottom view and adds it to a spacing view, footerView, and then calls showFooter. /// 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.rightAnchor.constraint(equalTo: bottomView.rightAnchor).isActive = true
footerView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor).isActive = true footerView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor).isActive = true
self.footerView = footerView self.footerView = footerView
showFooter() showFooter(nil)
} }
/// Takes the current headerView and adds it to the tableHeaderView /// Takes the current headerView and adds it to the tableHeaderView
func showHeader() { func showHeader(_ sizingWidth: CGFloat?) {
headerView?.removeFromSuperview() headerView?.removeFromSuperview()
tableView?.tableHeaderView = nil tableView?.tableHeaderView = nil
guard let headerView = headerView else { guard let headerView = headerView else {
@ -176,7 +177,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
} }
/// Takes the current footerView and adds it to the tableFooterView /// Takes the current footerView and adds it to the tableFooterView
func showFooter() { func showFooter(_ sizingWidth: CGFloat?) {
footerView?.removeFromSuperview() footerView?.removeFromSuperview()
safeAreaView?.removeFromSuperview() safeAreaView?.removeFromSuperview()
guard let footerView = footerView, let tableView = tableView else { guard let footerView = footerView, let tableView = tableView else {

View File

@ -71,8 +71,9 @@ NS_ASSUME_NONNULL_BEGIN
// Gets the constraint height to be whatever space is left in the scroll view. // 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; + (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:(nullable UIView *)view;
+ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width;
#pragma mark - Keyboard #pragma mark - Keyboard

View File

@ -119,7 +119,7 @@
#pragma mark - Sizing #pragma mark - Sizing
+ (CGFloat)getWidth { + (CGFloat)getWidth {
UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController ?: [UIApplication sharedApplication].keyWindow.rootViewController; UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController;
if (controller) { if (controller) {
return CGRectGetWidth(controller.view.bounds); return CGRectGetWidth(controller.view.bounds);
} else { } else {
@ -138,7 +138,7 @@
} }
+ (CGFloat)getHeightOfView:(nonnull UIView *)view forWidth:(nullable NSNumber *)width { + (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; return [view systemLayoutSizeFittingSize:CGSizeMake(floatWidth, UILayoutFittingCompressedSize.height) withHorizontalFittingPriority:1000 verticalFittingPriority:250].height;
} }
@ -192,6 +192,13 @@
view.frame = frame; 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 #pragma mark - Keyboard
+ (void)setScrollViewInsetForKeyboardShow:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController rectToScrollTo:(nonnull CGRect (^)(void))rectToScrollTo { + (void)setScrollViewInsetForKeyboardShow:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController rectToScrollTo:(nonnull CGRect (^)(void))rectToScrollTo {