Skip to content

Commit

Permalink
Add LearnAboutSizeClasses sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hyche committed Aug 11, 2017
1 parent 3505df9 commit 3654c32
Show file tree
Hide file tree
Showing 18 changed files with 858 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
FD9A93D81F3A921B00BAD905 /* EHAdjustableContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9A93D61F3A921B00BAD905 /* EHAdjustableContainerView.swift */; };
FD9A93D91F3A921B00BAD905 /* EHContainerSizeInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9A93D71F3A921B00BAD905 /* EHContainerSizeInfoView.swift */; };
FDB304DC1F3A9D250094181F /* EHUnsatisfiableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB304DB1F3A9D250094181F /* EHUnsatisfiableViewController.swift */; };
FDE8CA011F3BE78F006D6552 /* EHAmbiguousViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE8CA001F3BE78F006D6552 /* EHAmbiguousViewController.swift */; };
FDE8CA031F3C04DC006D6552 /* EHAutosizingMaskErrorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE8CA021F3C04DC006D6552 /* EHAutosizingMaskErrorViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -28,6 +30,8 @@
FD9A93D61F3A921B00BAD905 /* EHAdjustableContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHAdjustableContainerView.swift; sourceTree = "<group>"; };
FD9A93D71F3A921B00BAD905 /* EHContainerSizeInfoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHContainerSizeInfoView.swift; sourceTree = "<group>"; };
FDB304DB1F3A9D250094181F /* EHUnsatisfiableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHUnsatisfiableViewController.swift; sourceTree = "<group>"; };
FDE8CA001F3BE78F006D6552 /* EHAmbiguousViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHAmbiguousViewController.swift; sourceTree = "<group>"; };
FDE8CA021F3C04DC006D6552 /* EHAutosizingMaskErrorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EHAutosizingMaskErrorViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -69,6 +73,8 @@
FD9A93CD1F3A903900BAD905 /* LaunchScreen.storyboard */,
FD9A93D01F3A903900BAD905 /* Info.plist */,
FDB304DB1F3A9D250094181F /* EHUnsatisfiableViewController.swift */,
FDE8CA001F3BE78F006D6552 /* EHAmbiguousViewController.swift */,
FDE8CA021F3C04DC006D6552 /* EHAutosizingMaskErrorViewController.swift */,
);
path = DebuggingAutoLayout;
sourceTree = "<group>";
Expand Down Expand Up @@ -148,8 +154,10 @@
FD9A93D91F3A921B00BAD905 /* EHContainerSizeInfoView.swift in Sources */,
FD9A93D81F3A921B00BAD905 /* EHAdjustableContainerView.swift in Sources */,
FD9A93C71F3A903900BAD905 /* DetailViewController.swift in Sources */,
FDE8CA031F3C04DC006D6552 /* EHAutosizingMaskErrorViewController.swift in Sources */,
FD9A93C51F3A903900BAD905 /* MasterViewController.swift in Sources */,
FDB304DC1F3A9D250094181F /* EHUnsatisfiableViewController.swift in Sources */,
FDE8CA011F3BE78F006D6552 /* EHAmbiguousViewController.swift in Sources */,
FD9A93C31F3A903900BAD905 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-_UIConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-_UIConstraintBasedLayoutPlaySoundOnUnsatisfiable YES"
Expand Down
7 changes: 7 additions & 0 deletions DebuggingAutoLayout/DebuggingAutoLayout/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func showDebuggingInformationOverlay() {
let overlayClass = NSClassFromString("UIDebuggingInformationOverlay") as? UIWindow.Type
_ = overlayClass?.perform(NSSelectorFromString("prepareDebuggingOverlay"))
let overlay = overlayClass?.perform(NSSelectorFromString("overlay")).takeUnretainedValue() as? UIWindow
_ = overlay?.perform(NSSelectorFromString("toggleVisibility"))
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// EHAmbiguousViewController.swift
// DebuggingAutoLayout
//
// Created by Eric Hyche on 8/9/17.
// Copyright © 2017 HeirPlay Software. All rights reserved.
//

import UIKit

class EHAmbiguousViewController: UIViewController {

private let adjustable = EHAdjustableContainerView(frame: .zero)

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.title = "Ambiguous Layouts"

view.backgroundColor = UIColor.white

adjustable.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adjustable)

adjustable.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor).isActive = true
adjustable.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor).isActive = true
adjustable.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
adjustable.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true

let label0 = UILabel(frame: .zero)
label0.translatesAutoresizingMaskIntoConstraints = false
label0.backgroundColor = UIColor.purple
label0.textColor = UIColor.white
label0.font = UIFont.boldSystemFont(ofSize: 18.0)
label0.text = "This is a label"
adjustable.containerView.addSubview(label0)

// We intentionally "forget" to position
// label0.centerYAnchor.constraint(equalTo: adjustable.containerView.centerYAnchor).isActive = true
label0.widthAnchor.constraint(greaterThanOrEqualToConstant: 100.0).isActive = true
label0.leadingAnchor.constraint(equalTo: adjustable.containerView.layoutMarginsGuide.leadingAnchor).isActive = true
label0.trailingAnchor.constraint(equalTo: adjustable.containerView.layoutMarginsGuide.trailingAnchor).isActive = true

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// EHAutosizingMaskErrorViewController.swift
// DebuggingAutoLayout
//
// Created by Eric Hyche on 8/9/17.
// Copyright © 2017 HeirPlay Software. All rights reserved.
//

import UIKit

class EHAutosizingMaskErrorViewController: UIViewController {

private let adjustable = EHAdjustableContainerView(frame: .zero)

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.title = "Unsatisfiable Layouts"

view.backgroundColor = UIColor.white

adjustable.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(adjustable)

adjustable.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor).isActive = true
adjustable.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor).isActive = true
adjustable.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
adjustable.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true

let label0 = UILabel(frame: .zero)
// label0.translatesAutoresizingMaskIntoConstraints = false
label0.backgroundColor = UIColor.purple
label0.textColor = UIColor.white
label0.font = UIFont.boldSystemFont(ofSize: 18.0)
label0.text = "This is a label"
adjustable.containerView.addSubview(label0)

label0.centerYAnchor.constraint(equalTo: adjustable.containerView.centerYAnchor).isActive = true
label0.widthAnchor.constraint(greaterThanOrEqualToConstant: 100.0).isActive = true
label0.leadingAnchor.constraint(equalTo: adjustable.containerView.layoutMarginsGuide.leadingAnchor).isActive = true
label0.trailingAnchor.constraint(equalTo: adjustable.containerView.layoutMarginsGuide.trailingAnchor).isActive = true
}


}
19 changes: 14 additions & 5 deletions DebuggingAutoLayout/DebuggingAutoLayout/MasterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class MasterViewController: UITableViewController {
enum RowContent: Int {
case unsatisfiableLayouts
case ambiguousLayouts
case debuggingInformationOverlay
case autosizingMaskError
}

let cellID = "CellID"
Expand All @@ -36,7 +38,7 @@ class MasterViewController: UITableViewController {
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
return 4
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand All @@ -45,8 +47,10 @@ class MasterViewController: UITableViewController {
if let rowContent = RowContent(rawValue: indexPath.row) {
var title = ""
switch rowContent {
case .unsatisfiableLayouts: title = "Unsatisfiable Layouts"
case .ambiguousLayouts: title = "Ambiguous Layouts"
case .unsatisfiableLayouts: title = "Unsatisfiable Layouts"
case .ambiguousLayouts: title = "Ambiguous Layouts"
case .debuggingInformationOverlay: title = "Debugging Information Overlay"
case .autosizingMaskError: title = "Autoresizing Mask Errors"
}
cell.textLabel?.text = title
cell.accessoryType = .disclosureIndicator
Expand All @@ -65,9 +69,14 @@ class MasterViewController: UITableViewController {
switch rowContent {
case .unsatisfiableLayouts:
viewController = EHUnsatisfiableViewController(nibName: nil, bundle: nil)
break
case .ambiguousLayouts:
break
viewController = EHAmbiguousViewController(nibName: nil, bundle: nil)
case .debuggingInformationOverlay:
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.showDebuggingInformationOverlay()
}
case .autosizingMaskError:
viewController = EHAutosizingMaskErrorViewController(nibName: nil, bundle: nil)
}
if let viewController = viewController {
navigationController?.pushViewController(viewController, animated: true)
Expand Down
Loading

0 comments on commit 3654c32

Please sign in to comment.