Improvements to resizing/reorientation

This commit is contained in:
Charles Magahern
2019-10-13 15:40:13 -07:00
parent 1dca4b98e5
commit 6a8eec5a07
3 changed files with 102 additions and 31 deletions
@@ -18,8 +18,8 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
{
let url = URL(string: "http://midna.xionsf.com:5000")
_server = WemoServer(url!)
let url = URL(string: "http://midna.xionsf.com:5000")!
_server = WemoServer(url)
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
@@ -54,8 +54,6 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
super.viewDidLayoutSubviews()
let bounds = self.view.bounds
let horizontalSizeClass = self.traitCollection.horizontalSizeClass
let headerBounds = CGRect(
x: 0.0,
y: 0.0,
@@ -74,14 +72,14 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
let visualizationFrame = CGRect(
x: bodyBounds.origin.x,
y: bodyBounds.origin.y,
width: rint(0.55 * bodyBounds.size.width),
width: rint(0.5 * bodyBounds.size.width),
height: bodyBounds.size.height
)
_visualizationController.view.frame = visualizationFrame
var switchesOriginX: CGFloat = 0.0
var switchesWidth: CGFloat = 0.0
if (horizontalSizeClass == .regular) {
if (_visualizationShouldBeVisible()) {
switchesOriginX = visualizationFrame.maxX
switchesWidth = bodyBounds.size.width - visualizationFrame.size.width
} else {
@@ -102,6 +100,8 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
{
super.viewDidAppear(animated)
UIApplication.shared.isIdleTimerDisabled = true
_headerView.xionLogoView.beginAnimating()
if (!_server.connected) {
@@ -117,6 +117,12 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
}
}
override func viewDidDisappear(_ animated: Bool)
{
super.viewDidDisappear(animated)
UIApplication.shared.isIdleTimerDisabled = false
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
{
super.viewWillTransition(to: size, with: coordinator)
@@ -152,14 +158,23 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate
// MARK: Internal
internal func _visualizationShouldBeVisible() -> Bool
{
switch self.traitCollection.horizontalSizeClass {
case .regular:
return true
case .compact:
return false
default:
return false
}
}
internal func _updateSizeClassPresentation()
{
let horizontalSizeClass = self.traitCollection.horizontalSizeClass
if (horizontalSizeClass == .regular) {
_visualizationController.view.isHidden = false
} else {
_visualizationController.view.isHidden = true
}
_visualizationController.view.isHidden = !_visualizationShouldBeVisible()
}
internal func _updateVisualization(_ animated: Bool)