From 4e7a6bade58c9c4f23562d84f4849fd0ec8e964f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20Bal=C3=A1zs?= Date: Mon, 28 Oct 2019 00:08:31 +0100 Subject: [PATCH] Fix xib centering issues across different screen sizes --- .../App Flow/Joke/JokeTableViewController.swift | 17 +++++++++++------ .../Joke/UI/WaitingForFirstNotificationView.xib | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/BadJokes/App Flow/Joke/JokeTableViewController.swift b/BadJokes/App Flow/Joke/JokeTableViewController.swift index b044d0f..f93a31a 100644 --- a/BadJokes/App Flow/Joke/JokeTableViewController.swift +++ b/BadJokes/App Flow/Joke/JokeTableViewController.swift @@ -34,6 +34,11 @@ class JokeTableViewController: UIViewController { setObserverForUIApplicationDidBecomeActive() } + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + updateEmptyViewFrames() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) refreshData() @@ -110,23 +115,18 @@ private extension JokeTableViewController { private func presentEmptyView() { removeEmptyViews() + tableView.separatorStyle = dataSource.jokes.isEmpty ? .none : .singleLine if dataSource.jokes.isEmpty { - tableView.separatorStyle = .none - if DBService.shared.isSchedulesListEmpty() { displayViewInFrontOfTableView(frontview: noNotificationScheduledView) } else { displayViewInFrontOfTableView(frontview: waitingForFirstNotificationView) - waitingForFirstNotificationView.frame = UIScreen.main.bounds } - } else { - tableView.separatorStyle = .singleLine } } private func displayViewInFrontOfTableView(frontview view: UIView) { - view.frame = view.bounds tableView.addSubview(view) tableView.bringSubviewToFront(view) } @@ -135,6 +135,11 @@ private extension JokeTableViewController { noNotificationScheduledView.removeFromSuperview() waitingForFirstNotificationView.removeFromSuperview() } + + private func updateEmptyViewFrames() { + noNotificationScheduledView.frame = UIScreen.main.bounds + waitingForFirstNotificationView.frame = UIScreen.main.bounds + } } // MARK: - Navigation diff --git a/BadJokes/App Flow/Joke/UI/WaitingForFirstNotificationView.xib b/BadJokes/App Flow/Joke/UI/WaitingForFirstNotificationView.xib index 728534f..8498b39 100644 --- a/BadJokes/App Flow/Joke/UI/WaitingForFirstNotificationView.xib +++ b/BadJokes/App Flow/Joke/UI/WaitingForFirstNotificationView.xib @@ -14,8 +14,9 @@ - + +