From 8cd3f7fb3ace7716ec4c3261d0ce954f30ed8ec2 Mon Sep 17 00:00:00 2001 From: relikd Date: Fri, 4 Sep 2020 09:14:35 +0200 Subject: [PATCH] Fix iOS 10 layout issues --- main/Common Classes/NotificationBanner.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main/Common Classes/NotificationBanner.swift b/main/Common Classes/NotificationBanner.swift index 080923f..3972c94 100644 --- a/main/Common Classes/NotificationBanner.swift +++ b/main/Common Classes/NotificationBanner.swift @@ -30,13 +30,18 @@ struct NotificationBanner { img.tintColor = fg view.addSubview(lbl) view.addSubview(img) - img.anchor([.leading, .centerY], to: view.layoutMarginsGuide) + img.anchor([.centerY], to: view.layoutMarginsGuide) lbl.anchor([.top, .bottom, .trailing], to: view.layoutMarginsGuide) img.widthAnchor =&= 25 img.heightAnchor =&= 25 + if #available(iOS 11, *) { + img.leadingAnchor =&= view.layoutMarginsGuide.leadingAnchor + } else { + img.leadingAnchor =&= view.leadingAnchor + 8 + } lbl.leadingAnchor =&= img.trailingAnchor + 8 - img.bottomAnchor =<= view.bottomAnchor - 8 - lbl.bottomAnchor =<= view.bottomAnchor - 8 + img.bottomAnchor =<= view.bottomAnchor - 8 | .init(rawValue: 999) + lbl.bottomAnchor =<= view.bottomAnchor - 8 | .init(rawValue: 999) } /// Animate header banner from the top of the view. Show for `delay` seconds and then hide again. @@ -44,6 +49,7 @@ struct NotificationBanner { func present(in vc: UIViewController, hideAfter delay: TimeInterval = 3, onClose: (() -> Void)? = nil) { vc.view.addSubview(view) view.anchor([.leading, .trailing], to: vc.view!) + view.widthAnchor =&= vc.view!.widthAnchor // Bug? left-right is not sufficient vc.view.layoutIfNeeded() // sets the height let h = view.frame.height let constraint = view.topAnchor =&= vc.view.topAnchor - h