From bb8b05ce325454821b984b8684a1485b9bf12db1 Mon Sep 17 00:00:00 2001 From: Emanuel Guerrero Date: Fri, 23 Sep 2016 21:35:23 -0400 Subject: [PATCH] Converted to Swift 3. --- .DS_Store | Bin 0 -> 6148 bytes Example/.DS_Store | Bin 0 -> 6148 bytes Loader.xcodeproj/project.pbxproj | 3 +++ Source/.DS_Store | Bin 0 -> 6148 bytes Source/Loader.swift | 32 +++++++++++++++---------------- Source/Switch.swift | 6 +++--- 6 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 .DS_Store create mode 100644 Example/.DS_Store create mode 100644 Source/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2dcfb13eb34a612af0441d272e69e35cd1ff55ce GIT binary patch literal 6148 zcmeHK&2G~`5S~p#!`W$ z7|R83x1YprD7=5UaTp|NrSg;Imh#t@3r4ZDLYH~H^u+G)zMVR0FR3}*$D$T^zN_q} zlXfQdL(apg?YJj_-*1_#`#egWAo9C2p=YN-7OGdll)aAw+{iNNNy*S+E^qu!NmH|o=+0cw78g= z7FfMhQPbI2xzthhV44BVz*S&?)&~ofu&Qt*Q7j!;h$8@E9-D=rO+O73V=1gE97)6; z6edFvWhhfe3?{>|-BNy4g(HbF9GE(MFm-39PAE*=9mltXJFu!mU1|n21M>_l$*M{F zf8+1x|M?(Y(+p?^t`q|-U$^Tud?mHFF1#G=wHE4AR1)$VNfaSisO?x7v=y(R3c)^$ Y48*F!kwk1k(LVx$23=?d{wV{$0huoeApigX literal 0 HcmV?d00001 diff --git a/Example/.DS_Store b/Example/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..201d8647bf2ea9be44e1f53bdc4e1180e7db2f02 GIT binary patch literal 6148 zcmeHKyH3ME5S$G`3ZWo$DP2-U;txzPNNGW$h6D$J3`TJfl>Q7piVxs#V0P~mh?BGk z(5|&N=k?A#<}9BNfDE6m4}l(l4qdUe!(xr;bM+N##mF{Mtc@H6a@^nw^ObB5{6+YD96m!SLKv`@L|Rpu*ViEUOCsjBJTwgz5|O$ zgZIE2Map_ z5Zer!v93Re%1I)o5$k|_LX$ux2CBp(h6Fm}Nz6+l)&T<@5)U5|dzN@Y5$m1pCzcLL z1A6HSxB|-xY=zsN?*Av7&;QFLzjFm#fq$idw6pVU$SK9Wb!Bq8*CzB!x|-(I0T&cj hY%6B2ZpD4N8RLmoh-t(+AR{#Y5il9Na0Px;flq^TT*3eV literal 0 HcmV?d00001 diff --git a/Loader.xcodeproj/project.pbxproj b/Loader.xcodeproj/project.pbxproj index 23f5753..ac63aa1 100644 --- a/Loader.xcodeproj/project.pbxproj +++ b/Loader.xcodeproj/project.pbxproj @@ -107,6 +107,7 @@ TargetAttributes = { BE3156731C149D0F00BA4E59 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0800; }; }; }; @@ -258,6 +259,7 @@ PRODUCT_BUNDLE_IDENTIFIER = Ekhoo.Loader; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -271,6 +273,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Ekhoo.Loader; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Source/.DS_Store b/Source/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b4f8732ea04b804eb925d3fb4cd443443df209c1 GIT binary patch literal 6148 zcmeHKO-lnY5PhQ+3VP_#V~(B#|3NHO5IosGplvM*g@v}_b$_7$N#A@Z)?IHRA~Q?o zWs`YH_Q56@05X1BoB<;MLl#BRN{?xCZ`WP~?-Rww*j}xg`E1q9dWQL%O}h32oMXf1 z9-r5*l3cQ!yqekak8q6!cUUlXjZ<=-@rY%I_tN1_Epm%F9=_+v%@>|cnl2Sc1yX@j zAQkvg1$btw4G$gDrvj-!D)6Cz?hl1Uu?Dt|wsp{13P2pN*^G6)I4h?F*1*=0Jv4DD z(Ww$ChB%$=CE{ve>*#byBp(tpzb7wZvvd4n;gIT>J{3p>b`{Xvmp0P#|AN0vZ<22z z=~97I;J+#$gUNI<=GVp9+WAgBYYWRQi<-u@TA{JNa|z&!?jy(6>HS6PjH`jIqmH8O QMknS)zywK`3jBfsZ;1~!`2YX_ literal 0 HcmV?d00001 diff --git a/Source/Loader.swift b/Source/Loader.swift index 66ad73b..c9b20c0 100644 --- a/Source/Loader.swift +++ b/Source/Loader.swift @@ -14,7 +14,7 @@ public class Loader: UIView { private var switchView: UIView? private var switchAnimationSide: Bool = false - private var animationTimer: NSTimer? + private var animationTimer: Timer? var loaderColor: UIColor { didSet { @@ -30,17 +30,17 @@ public class Loader: UIView { } override init(frame: CGRect) { - self.loaderColor = UIColor.whiteColor() - self.switchColor = UIColor(red: 175.0 / 255.0, green: 85.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0) + self.loaderColor = UIColor.white + self.switchColor = UIColor(red: 255.0 / 255.0, green: 195.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0) super.init(frame: frame) - self.switchView = UIView(frame: CGRectMake(kInset, kInset, frame.size.height - 2 * kInset, frame.size.height - 2 * kInset)) + self.switchView = UIView(frame: CGRect(x: kInset, y: kInset, width: frame.size.height - 2 * kInset, height: frame.size.height - 2 * kInset)) self.switchView!.backgroundColor = self.switchColor self.switchView!.layer.cornerRadius = round(self.switchView!.frame.size.width / 2) self.switchView!.layer.masksToBounds = true - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.addSubview(self.switchView!) } @@ -54,24 +54,24 @@ public class Loader: UIView { return; } - UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.AllowAnimatedContent, animations: { () -> Void in + UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions.allowAnimatedContent, animations: { () -> Void in let frame: CGRect = self.bounds if self.switchView!.frame.origin.x > kInset { - self.switchView!.frame = CGRectMake(kInset, self.switchView!.frame.origin.y, frame.width - 2 * kInset, self.switchView!.frame.height) + self.switchView!.frame = CGRect(x: kInset, y: self.switchView!.frame.origin.y, width: frame.width - 2 * kInset, height: self.switchView!.frame.height) } else { - self.switchView!.frame = CGRectMake(self.switchView!.frame.origin.x, self.switchView!.frame.origin.y, frame.width - 2 * kInset, self.switchView!.frame.height) + self.switchView!.frame = CGRect(x: self.switchView!.frame.origin.x, y: self.switchView!.frame.origin.y, width: frame.width - 2 * kInset, height: self.switchView!.frame.height) } self.switchView!.setNeedsDisplay() }) { (finished) -> Void in - UIView.animateWithDuration(0.30, animations: { () -> Void in + UIView.animate(withDuration: 0.30, animations: { () -> Void in let frame: CGRect = self.bounds if self.switchAnimationSide { - self.switchView!.frame = CGRectMake(kInset, self.switchView!.frame.origin.y, self.switchView!.frame.size.height, self.switchView!.frame.height) + self.switchView!.frame = CGRect(x: kInset, y: self.switchView!.frame.origin.y, width: self.switchView!.frame.size.height, height: self.switchView!.frame.height) } else { - self.switchView!.frame = CGRectMake(frame.size.width - self.switchView!.frame.height - kInset, self.switchView!.frame.origin.y, self.switchView!.frame.size.height, self.switchView!.frame.height) + self.switchView!.frame = CGRect(x: frame.size.width - self.switchView!.frame.height - kInset, y: self.switchView!.frame.origin.y, width: self.switchView!.frame.size.height, height: self.switchView!.frame.height) } self.switchAnimationSide = !self.switchAnimationSide @@ -82,15 +82,15 @@ public class Loader: UIView { } @objc private func animateLoader() { - UIView.animateWithDuration(0.4) { () -> Void in - self.transform = CGAffineTransformRotate(self.transform, CGFloat(M_PI_2)); + UIView.animate(withDuration: 0.4) { () -> Void in + self.transform = self.transform.rotated(by: CGFloat(M_PI_2)); } animateSwitch() } public func startAnimating() { - self.animationTimer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: "animateLoader", userInfo: nil, repeats: true) + self.animationTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: "animateLoader", userInfo: nil, repeats: true) } public func stopAnimating() { @@ -101,8 +101,8 @@ public class Loader: UIView { } } - override public func drawRect(rect: CGRect) { - let rectanglePath = UIBezierPath(roundedRect: CGRectMake(0.0, 0.0, rect.size.width, rect.size.height), cornerRadius: round(rect.size.width / 2.0)) + override public func draw(_ rect: CGRect) { + let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0.0, y: 0.0, width: rect.size.width, height: rect.size.height), cornerRadius: round(rect.size.width / 2.0)) self.loaderColor.setFill() rectanglePath.fill() } diff --git a/Source/Switch.swift b/Source/Switch.swift index cb9db76..41ef84e 100644 --- a/Source/Switch.swift +++ b/Source/Switch.swift @@ -14,15 +14,15 @@ class Switch: UIView { override init(frame: CGRect) { super.init(frame: frame) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - override func drawRect(rect: CGRect) { - let rectanglePath = UIBezierPath(roundedRect: CGRectMake(0.0, 0.0, rect.size.width, rect.size.height), cornerRadius: rect.size.width / 2.0) + override func draw(_ rect: CGRect) { + let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0.0, y: 0.0, width: rect.size.width, height: rect.size.height), cornerRadius: rect.size.width / 2.0) self.switchColor.setFill() rectanglePath.fill() }