-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b6eea3e
Showing
15 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
InteractivePlayground.playground/Pages/Animated Buttons.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//: [Previous](@previous) | ||
|
||
import UIKit | ||
import XCPlayground | ||
|
||
class ViewController: UIViewController { | ||
|
||
var allButtons: [UIButton]? | ||
|
||
override func viewDidLoad() { | ||
view.backgroundColor = .whiteColor() | ||
view.tintColor = UIColor.whiteColor() | ||
|
||
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Show/Hide", style: .Plain, target: self, action: "animate") | ||
} | ||
|
||
func animate() { | ||
if let allButtons = allButtons { | ||
hideButtons(allButtons) | ||
} else { | ||
showButtons() | ||
} | ||
} | ||
|
||
func showButtons() { | ||
let makeButtonWithTitle = { (title: String) -> UIButton in | ||
let button = UIButton(type: .System) | ||
button.backgroundColor = .brownColor() | ||
button.setTitle(title, forState: .Normal) | ||
button.layer.cornerRadius = 5 | ||
return button | ||
} | ||
|
||
let aButton = makeButtonWithTitle("Option a") | ||
let bButton = makeButtonWithTitle("Option b") | ||
let cButton = makeButtonWithTitle("Option c") | ||
|
||
allButtons = [aButton, bButton, cButton] | ||
|
||
guard let allButtons = allButtons else { fatalError() } | ||
|
||
for button in allButtons.reverse() { | ||
button.frame = CGRect(x: 10, y: -40, width: view.frame.size.width-20, height: 40) | ||
view.addSubview(button) | ||
} | ||
|
||
for (index, button) in allButtons.enumerate() { | ||
|
||
UIView.animateWithDuration(0.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: [], animations: { | ||
|
||
button.frame.origin.y = 60 + CGFloat(index) * (button.frame.size.height + 10) | ||
}) { (_) in | ||
|
||
} | ||
} | ||
} | ||
|
||
func hideButtons(buttons: [UIButton]) { | ||
for button in buttons { | ||
UIView.animateWithDuration(0.5, animations: { | ||
button.frame.origin.y = -40 | ||
button.alpha = 0 | ||
}, completion: { (_) in | ||
button.removeFromSuperview() | ||
}) | ||
} | ||
self.allButtons = nil | ||
} | ||
} | ||
|
||
let navigationController = UINavigationController(rootViewController: ViewController()) | ||
|
||
navigationController.view.frame.size = CGSize(width: 320, height: 400) | ||
navigationController.navigationBar.barTintColor = .whiteColor() | ||
|
||
XCPlaygroundPage.currentPage.liveView = navigationController.view | ||
|
||
//: [Next](@next) |
6 changes: 6 additions & 0 deletions
6
InteractivePlayground.playground/Pages/Animated Buttons.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
81 changes: 81 additions & 0 deletions
81
InteractivePlayground.playground/Pages/Gesture Recognizer.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//: [Previous](@previous) | ||
|
||
import UIKit | ||
import XCPlayground | ||
|
||
class View: UIView { | ||
|
||
let label: UILabel | ||
|
||
override init(frame: CGRect) { | ||
|
||
label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.font = UIFont.systemFontOfSize(20) | ||
label.text = "Do something" | ||
label.numberOfLines = 0 | ||
label.textAlignment = .Center | ||
|
||
super.init(frame: frame) | ||
|
||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tap:")) | ||
|
||
let leftSwipeRecogniser = UISwipeGestureRecognizer(target: self, action: "swipe:") | ||
leftSwipeRecogniser.direction = UISwipeGestureRecognizerDirection.Left | ||
addGestureRecognizer(leftSwipeRecogniser) | ||
|
||
let rightSwipeRecogniser = UISwipeGestureRecognizer(target: self, action: "swipe:") | ||
rightSwipeRecogniser.direction = UISwipeGestureRecognizerDirection.Right | ||
addGestureRecognizer(rightSwipeRecogniser) | ||
|
||
let panRecognizer = UIPanGestureRecognizer(target: self, action: "pan:") | ||
panRecognizer.requireGestureRecognizerToFail(leftSwipeRecogniser) | ||
panRecognizer.requireGestureRecognizerToFail(rightSwipeRecogniser) | ||
addGestureRecognizer(panRecognizer) | ||
|
||
backgroundColor = UIColor.whiteColor() | ||
|
||
addSubview(label) | ||
|
||
label.leadingAnchor.constraintEqualToAnchor(leadingAnchor).active = true | ||
label.trailingAnchor.constraintEqualToAnchor(trailingAnchor).active = true | ||
label.centerYAnchor.constraintEqualToAnchor(centerYAnchor).active = true | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func tap(sender: UITapGestureRecognizer) { | ||
label.text = "tap" | ||
} | ||
|
||
func swipe(sender: UISwipeGestureRecognizer) { | ||
let directionString: String | ||
switch sender.direction { | ||
case UISwipeGestureRecognizerDirection.Left: | ||
directionString = "left" | ||
case UISwipeGestureRecognizerDirection.Up: | ||
directionString = "up" | ||
case UISwipeGestureRecognizerDirection.Right: | ||
directionString = "right" | ||
case UISwipeGestureRecognizerDirection.Down: | ||
directionString = "down" | ||
default: | ||
directionString = "w00t?" | ||
} | ||
|
||
label.text = "swipe \(directionString)" | ||
} | ||
|
||
func pan(sender: UIPanGestureRecognizer) { | ||
label.text = "pan with velocity:\nx: \(sender.velocityInView(self).x)\ny: \(sender.velocityInView(self).y)" | ||
} | ||
|
||
} | ||
|
||
let view = View(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) | ||
|
||
XCPlaygroundPage.currentPage.liveView = view | ||
|
||
//: [Next](@next) |
6 changes: 6 additions & 0 deletions
6
...activePlayground.playground/Pages/Gesture Recognizer.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
41 changes: 41 additions & 0 deletions
41
InteractivePlayground.playground/Pages/Push View Controller.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//: Playground - noun: a place where people can play | ||
|
||
import UIKit | ||
import XCPlayground | ||
|
||
class TableViewController: UITableViewController { | ||
|
||
override func viewDidLoad() { | ||
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell") | ||
} | ||
|
||
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return 10 | ||
} | ||
|
||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) | ||
|
||
cell.textLabel?.text = "Row: \(indexPath.row)" | ||
|
||
return cell | ||
} | ||
|
||
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | ||
let next = TableViewController() | ||
next.title = "Row: \(indexPath.row)" | ||
navigationController?.pushViewController(next, animated: true) | ||
|
||
print(navigationController?.viewControllers.count) | ||
} | ||
} | ||
|
||
let tableViewController = TableViewController() | ||
tableViewController.title = "start" | ||
let navigationController = UINavigationController(rootViewController: tableViewController) | ||
|
||
navigationController.view.frame.size = CGSize(width: 320, height: 400) | ||
navigationController.navigationBar.barTintColor = .whiteColor() | ||
|
||
XCPlaygroundPage.currentPage.liveView = navigationController.view | ||
|
6 changes: 6 additions & 0 deletions
6
...tivePlayground.playground/Pages/Push View Controller.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
59 changes: 59 additions & 0 deletions
59
InteractivePlayground.playground/Pages/Text Input.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//: [Previous](@previous) | ||
|
||
import UIKit | ||
import XCPlayground | ||
|
||
class View: UIView { | ||
|
||
let textField: UITextField | ||
let label: UILabel | ||
|
||
override init(frame: CGRect) { | ||
|
||
textField = UITextField() | ||
textField.backgroundColor = UIColor.yellowColor() | ||
textField.placeholder = "Type something" | ||
|
||
label = UILabel() | ||
label.backgroundColor = UIColor.blackColor() | ||
label.textColor = UIColor.whiteColor() | ||
label.text = " " | ||
|
||
let button = UIButton(type: .System) | ||
button.setTitle("I'm a button!", forState: .Normal) | ||
button.tintColor = UIColor.whiteColor() | ||
|
||
let stackView = UIStackView(arrangedSubviews: [textField, label, button]) | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
stackView.axis = .Vertical | ||
stackView.distribution = .EqualSpacing | ||
stackView.spacing = 10 | ||
|
||
super.init(frame: frame) | ||
|
||
backgroundColor = UIColor.brownColor() | ||
|
||
addSubview(stackView) | ||
button.addTarget(self, action: "changeLabelText", forControlEvents: .TouchUpInside) | ||
|
||
let views = ["stackView": stackView] | ||
var layoutConstraints = [NSLayoutConstraint]() | ||
layoutConstraints += NSLayoutConstraint.constraintsWithVisualFormat("|-[stackView]-|", options: [], metrics: nil, views: views) | ||
layoutConstraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-[stackView]", options: [], metrics: nil, views: views) | ||
NSLayoutConstraint.activateConstraints(layoutConstraints) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func changeLabelText() { | ||
label.text = textField.text | ||
} | ||
} | ||
|
||
let hostView = View(frame: CGRect(x: 0, y: 0, width: 320, height: 200)) | ||
|
||
XCPlaygroundPage.currentPage.liveView = hostView | ||
|
||
//: [Next](@next) |
6 changes: 6 additions & 0 deletions
6
InteractivePlayground.playground/Pages/Text Input.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='6.0' target-platform='ios'> | ||
<pages> | ||
<page name='Push View Controller'/> | ||
<page name='Animated Buttons'/> | ||
<page name='Gesture Recognizer'/> | ||
</pages> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
InteractivePlayground.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+16.8 KB
...ayground/playground.xcworkspace/xcuserdata/dom.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.