From 23e705a05d977d0c14bf58547e17072b6740e7dc Mon Sep 17 00:00:00 2001 From: Matt Neuburg Date: Sat, 16 Jul 2016 19:14:24 -0700 Subject: [PATCH] minor tweaks to some book 2 chapter 1 examples --- .../CancelableTimer.swift | 1 + .../AppDelegate.swift | 7 ++++++- .../Base.lproj/Main.storyboard | 13 ++++++++----- bk2ch01p013bounds/ch14p371frame/AppDelegate.swift | 13 ++++++++++++- .../CoordinateSpaceTest/ViewController.swift | 6 ++++-- .../ch14p371frame/AppDelegate.swift | 13 ++++++------- 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift b/bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift index 34bdff243..75a3a001e 100644 --- a/bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift +++ b/bk1ch12p499cancelableTimer/ch12p325NotificationLeaker/CancelableTimer.swift @@ -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 diff --git a/bk2ch01p006customWindowInStoryboardApp/ch14p366customWindowInStoryboardApp/AppDelegate.swift b/bk2ch01p006customWindowInStoryboardApp/ch14p366customWindowInStoryboardApp/AppDelegate.swift index 853c37ed2..50cbab1a7 100644 --- a/bk2ch01p006customWindowInStoryboardApp/ch14p366customWindowInStoryboardApp/AppDelegate.swift +++ b/bk2ch01p006customWindowInStoryboardApp/ch14p366customWindowInStoryboardApp/AppDelegate.swift @@ -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 } -} \ No newline at end of file +} diff --git a/bk2ch01p009experimenting1/bk2ch01p009experimenting1/Base.lproj/Main.storyboard b/bk2ch01p009experimenting1/bk2ch01p009experimenting1/Base.lproj/Main.storyboard index 3a2a49bad..3be24b94c 100644 --- a/bk2ch01p009experimenting1/bk2ch01p009experimenting1/Base.lproj/Main.storyboard +++ b/bk2ch01p009experimenting1/bk2ch01p009experimenting1/Base.lproj/Main.storyboard @@ -1,25 +1,28 @@ - + - + + + - + - + - + + diff --git a/bk2ch01p013bounds/ch14p371frame/AppDelegate.swift b/bk2ch01p013bounds/ch14p371frame/AppDelegate.swift index c1f17e88e..81a0579ba 100644 --- a/bk2ch01p013bounds/ch14p371frame/AppDelegate.swift +++ b/bk2ch01p013bounds/ch14p371frame/AppDelegate.swift @@ -11,7 +11,7 @@ extension CGRect { var window : UIWindow? - let which = 1 + let which = 4 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { @@ -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 } diff --git a/bk2ch01p015coordinateSpace/CoordinateSpaceTest/ViewController.swift b/bk2ch01p015coordinateSpace/CoordinateSpaceTest/ViewController.swift index 30abefa4b..948a27085 100644 --- a/bk2ch01p015coordinateSpace/CoordinateSpaceTest/ViewController.swift +++ b/bk2ch01p015coordinateSpace/CoordinateSpaceTest/ViewController.swift @@ -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 { @@ -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 { diff --git a/bk2ch01p017transform/ch14p371frame/AppDelegate.swift b/bk2ch01p017transform/ch14p371frame/AppDelegate.swift index 84f2838cc..6bc7ec169 100644 --- a/bk2ch01p017transform/ch14p371frame/AppDelegate.swift +++ b/bk2ch01p017transform/ch14p371frame/AppDelegate.swift @@ -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 { @@ -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: @@ -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)) @@ -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)) @@ -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) @@ -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)