Skip to content

Commit

Permalink
Fix xib centering issues across different screen sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
balazs630 committed Oct 27, 2019
1 parent 4ee0650 commit 4e7a6ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions BadJokes/App Flow/Joke/JokeTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class JokeTableViewController: UIViewController {
setObserverForUIApplicationDidBecomeActive()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
updateEmptyViewFrames()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
refreshData()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ccL-9h-tBC" userLabel="Content view">
<view contentMode="scaleToFill" id="ccL-9h-tBC" userLabel="Content view">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hamarosan 
kacagni fogsz... 😃" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eNE-YX-ppF">
<rect key="frame" x="75" y="300" width="225.5" height="67"/>
Expand Down

0 comments on commit 4e7a6ba

Please sign in to comment.