Skip to content

Commit

Permalink
minor tweaks to some book 2 chapter 1 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mattneub committed Jul 17, 2016
1 parent aa1f676 commit 23e705a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CancelableTimer: NSObject {
self.cancel()
self.timer = DispatchSource.timer(queue: self.q)
self.timer.scheduleRepeating(wallDeadline: DispatchWallTime.now(), interval: interval)
// self.timer.scheduleRepeating(deadline: .now(), interval: 1, leeway: .milliseconds(1))
self.timer.setEventHandler {
if self.firsttime {
self.firsttime = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import UIKit
var window : UIWindow? = MyWindow() // seems this is all we need

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("enter")
print(self.window?.rootViewController)
defer {
print("exit") // appears _before_ symbolic breakpoint on `makeKeyAndVisible`
}
return true
}


}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11163.2" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11133"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="bk2ch01p009experimenting1" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="319" y="96"/>
</scene>
</scenes>
</document>
13 changes: 12 additions & 1 deletion bk2ch01p013bounds/ch14p371frame/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension CGRect {

var window : UIWindow?

let which = 1
let which = 4

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

Expand Down Expand Up @@ -50,6 +50,17 @@ extension CGRect {

v1.bounds.origin.x += 10
v1.bounds.origin.y += 10

case 4:
// showing how to center a view in its superview
let v1 = UIView(frame:CGRect(113, 111, 132, 194))
v1.backgroundColor = UIColor(red: 1, green: 0.4, blue: 1, alpha: 1)
let v2 = UIView(frame:CGRect(0,0,20,20))
v2.backgroundColor = UIColor(red: 0.5, green: 1, blue: 0, alpha: 1)
mainview.addSubview(v1)
v1.addSubview(v2)
v2.center = v1.convert(v1.center, from:v1.superview)


default: break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class ViewController: UIViewController {

@IBAction func doButton1(_ sender: UIButton) {
let v = sender
let r = v.superview!.convert(v.frame, to: UIScreen.main().fixedCoordinateSpace)
let screen = UIScreen.main().fixedCoordinateSpace
let r = v.superview!.convert(v.frame, to: screen)
print(r)
print(v.frame)
do {
Expand All @@ -18,7 +19,8 @@ class ViewController: UIViewController {
}
@IBAction func doButton2(_ sender: UIButton) {
let v = sender
let r = v.superview!.convert(v.frame, to: UIScreen.main().fixedCoordinateSpace)
let screen = UIScreen.main().fixedCoordinateSpace
let r = v.superview!.convert(v.frame, to: screen)
print(r)
print(v.frame)
do {
Expand Down
13 changes: 6 additions & 7 deletions bk2ch01p017transform/ch14p371frame/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ extension CGRect {
}
}


@UIApplicationMain class AppDelegate : UIResponder, UIApplicationDelegate {

var window : UIWindow?

let which = 6
let which = 4

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

Expand All @@ -31,7 +30,7 @@ extension CGRect {
mainview.addSubview(v1)
v1.addSubview(v2)

v1.transform = CGAffineTransform(rotationAngle:45 * .pi/180.0)
v1.transform = CGAffineTransform(rotationAngle:45 * .pi/180)
print(v1.frame)

case 2:
Expand All @@ -52,7 +51,7 @@ extension CGRect {
mainview.addSubview(v1)
v1.addSubview(v2)

v2.transform = CGAffineTransform(translationX:100, y:0).rotate(45 * .pi/180.0)
v2.transform = CGAffineTransform(translationX:100, y:0).rotate(45 * .pi/180)

case 4:
let v1 = UIView(frame:CGRect(20, 111, 132, 194))
Expand All @@ -62,7 +61,7 @@ extension CGRect {
mainview.addSubview(v1)
v1.addSubview(v2)

v2.transform = CGAffineTransform(rotationAngle:45 * .pi/180.0).translateBy(x: 100, y: 0)
v2.transform = CGAffineTransform(rotationAngle:45 * .pi/180).translateBy(x: 100, y: 0)

case 5: // same as case 4 but using concat
let v1 = UIView(frame:CGRect(20, 111, 132, 194))
Expand All @@ -72,7 +71,7 @@ extension CGRect {
mainview.addSubview(v1)
v1.addSubview(v2)

let r = CGAffineTransform(rotationAngle:45 * .pi/180.0)
let r = CGAffineTransform(rotationAngle:45 * .pi/180)
let t = CGAffineTransform(translationX:100, y:0)
v2.transform = t.concat(r) // not r.concat(t)

Expand All @@ -84,7 +83,7 @@ extension CGRect {
mainview.addSubview(v1)
v1.addSubview(v2)

let r = CGAffineTransform(rotationAngle:45 * .pi/180.0)
let r = CGAffineTransform(rotationAngle:45 * .pi/180)
let t = CGAffineTransform(translationX:100, y:0)
v2.transform = t.concat(r)
v2.transform = r.invert().concat(v2.transform)
Expand Down

0 comments on commit 23e705a

Please sign in to comment.