From a061244a520bc8a6df260b212a53f8ea2369cbae Mon Sep 17 00:00:00 2001 From: realModusOperandi Date: Fri, 13 Oct 2017 16:42:36 -0500 Subject: [PATCH] Update to Swift 4 --- Animation.xcodeproj/project.pbxproj | 10 +- .../contents.xcworkspacedata | 7 + Animation/Base.lproj/Main.storyboard | 34 +++-- Animation/CubicBezier.swift | 21 +-- .../DropdownAppearTransitioning.swift | 12 +- .../DropdownDismissTransitioning.swift | 18 +-- .../DropdownExampleViewController.swift | 48 +++--- .../Dropdown/DropdownViewController.swift | 42 +++--- Animation/ExampleNobelViewController.swift | 99 ++++++------ .../AppIcon.appiconset/Contents.json | 30 ++++ Animation/LayoutConstraintAnimator.swift | 26 ++-- Animation/LayoutConstraintEasing.swift | 16 +- Animation/MainNavigationViewController.swift | 8 +- Animation/MainViewController.swift | 42 +++--- Animation/Modal/Modal.storyboard | 141 +++++++++--------- .../Modal/ModalAppearTransitioning.swift | 12 +- .../Modal/ModalDismissTransitioning.swift | 18 +-- .../Modal/ModalExampleViewController.swift | 16 +- Animation/Modal/ModalViewController.swift | 74 ++++----- Animation/Other/Button.swift | 2 +- Animation/Other/View.swift | 2 +- Animation/Search/Search.storyboard | 120 ++++++++------- .../Search/SearchExampleViewController.swift | 100 ++++++------- Animation/StyleKit/MotionStyleKit.swift | 4 +- Animation/TabBar/TabBarController.swift | 68 ++++----- .../TabBarExampleAnimatedTransitioning.swift | 32 ++-- .../TabBar/TabBarPeopleViewController.swift | 4 +- Animation/Table/TableView.swift | 6 +- Animation/Table/TableViewCell.swift | 2 +- Animation/Table/TableViewHeaderCell.swift | 2 +- Animation/ViewAnimator.swift | 6 +- 31 files changed, 546 insertions(+), 476 deletions(-) create mode 100644 Animation.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Animation.xcodeproj/project.pbxproj b/Animation.xcodeproj/project.pbxproj index 6099f42..25ce259 100644 --- a/Animation.xcodeproj/project.pbxproj +++ b/Animation.xcodeproj/project.pbxproj @@ -461,7 +461,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -499,7 +499,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; PROVISIONING_PROFILE = "2dcdcae7-9a9f-4d6c-b29b-03baf133e47d"; SDKROOT = iphoneos; @@ -524,11 +524,12 @@ "$(PROJECT_DIR)", ); INFOPLIST_FILE = Animation/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = Animation; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Debug; @@ -549,11 +550,12 @@ "$(PROJECT_DIR)", ); INFOPLIST_FILE = Animation/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = Animation; PROVISIONING_PROFILE = ""; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Release; diff --git a/Animation.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Animation.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Animation.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Animation/Base.lproj/Main.storyboard b/Animation/Base.lproj/Main.storyboard index 62baa94..b1ccc8f 100644 --- a/Animation/Base.lproj/Main.storyboard +++ b/Animation/Base.lproj/Main.storyboard @@ -1,9 +1,21 @@ - - + + + + + - + + + + + HelveticaNeue-Bold + + + HelveticaNeue-Light + + @@ -17,7 +29,7 @@ - + @@ -45,16 +57,16 @@ - + - + - + - + @@ -129,7 +141,6 @@ - @@ -146,7 +157,6 @@ - diff --git a/Animation/CubicBezier.swift b/Animation/CubicBezier.swift index fe27d96..1265592 100644 --- a/Animation/CubicBezier.swift +++ b/Animation/CubicBezier.swift @@ -12,10 +12,10 @@ class CubicBezier: NSObject { init(x1: CGFloat, y1: CGFloat, x2: CGFloat, y2: CGFloat) { - let normalizedPoint = CGPointZero; + _ = CGPoint.zero; - var p1 = CGPointZero - var p2 = CGPointZero + var p1 = CGPoint.zero + var p2 = CGPoint.zero // Clamp to interval [0..1] p1.x = max(0.0, min(1.0, x1)) @@ -37,8 +37,8 @@ class CubicBezier: NSObject { func valueForX(x: CGFloat) -> CGFloat { let epsilon: CGFloat = 1.0 / 200.0 - let xSolved = solveCurveX(x, epsilon: epsilon) - let y = sampleCurveY(xSolved) + let xSolved = solveCurveX(x: x, epsilon: epsilon) + let y = sampleCurveY(t: xSolved) return y; } @@ -46,15 +46,16 @@ class CubicBezier: NSObject { var t0: CGFloat, t1: CGFloat, t2: CGFloat, x2: CGFloat, d2: CGFloat - var i: Int = 0; + var _: Int = 0; // First try a few iterations of Newton's method -- normally very fast. - for (t2 = x, i = 0; i < 8; i++) { - x2 = sampleCurveX(t2) - x + t2 = x + for _ in 0..<8 { + x2 = sampleCurveX(t: t2) - x if (fabs(x2) < epsilon) { return t2; } - d2 = sampleCurveDerivativeX(t2) + d2 = sampleCurveDerivativeX(t: t2) if (fabs(d2) < 1e-6) { break; } @@ -74,7 +75,7 @@ class CubicBezier: NSObject { } while (t0 < t1) { - x2 = sampleCurveX(t2) + x2 = sampleCurveX(t: t2) if (fabs(x2 - x) < epsilon) { return t2; } diff --git a/Animation/Dropdown/DropdownAppearTransitioning.swift b/Animation/Dropdown/DropdownAppearTransitioning.swift index 1492dd8..ae261d9 100644 --- a/Animation/Dropdown/DropdownAppearTransitioning.swift +++ b/Animation/Dropdown/DropdownAppearTransitioning.swift @@ -8,21 +8,21 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac class DropdownAppearTransitioning: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.8 } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { - let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! DropdownViewController + let to = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as! DropdownViewController - let container = transitionContext.containerView() - let duration = transitionDuration(transitionContext) + let container = transitionContext.containerView + _ = transitionDuration(using: transitionContext) container.addSubview(to.view) to.show() { - transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) + transitionContext.completeTransition(!transitionContext.transitionWasCancelled) } } diff --git a/Animation/Dropdown/DropdownDismissTransitioning.swift b/Animation/Dropdown/DropdownDismissTransitioning.swift index 2726792..4634ef3 100644 --- a/Animation/Dropdown/DropdownDismissTransitioning.swift +++ b/Animation/Dropdown/DropdownDismissTransitioning.swift @@ -8,28 +8,28 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac class DropdownDismissTransitioning: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.8 } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { - let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! - let from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as! DropdownViewController + let to = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! + let from = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as! DropdownViewController - let container = transitionContext.containerView() - let duration = transitionDuration(transitionContext) + let container = transitionContext.containerView + _ = transitionDuration(using: transitionContext) - container.insertSubview(to.view, atIndex: 0) + container.insertSubview(to.view, at: 0) from.hide() { - transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) + transitionContext.completeTransition(!transitionContext.transitionWasCancelled) // Because the From View Controller disappears using UIViewControllerContextTransitioning, // re-add the toViewController's view as a subview of the key window's. // This is a solution for an iOS 8 bug. For details, see: // http://stackoverflow.com/questions/24338700/from-view-controller-disappears-using-uiviewcontrollercontexttransitioning - UIApplication.sharedApplication().keyWindow!.addSubview(to.view) + UIApplication.shared.keyWindow!.addSubview(to.view) } } diff --git a/Animation/Dropdown/DropdownExampleViewController.swift b/Animation/Dropdown/DropdownExampleViewController.swift index 4354e56..4fee570 100644 --- a/Animation/Dropdown/DropdownExampleViewController.swift +++ b/Animation/Dropdown/DropdownExampleViewController.swift @@ -44,7 +44,7 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon UIImage(named: "circle_x_06")!, UIImage(named: "circle_x_07")! ]; - var reversedAnimationImages: [UIImage] { get { return reverse(animationImages) } } + var reversedAnimationImages: [UIImage] { get { return animationImages.reversed() } } var hiddenStatusBar:Bool = false { didSet { @@ -65,12 +65,12 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon dropdownButtonImage.animationDuration = Double(self.animationImages.count) / 50.0; dropdownButtonImage.animationRepeatCount = 1; } - - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - dropdownVC = segue.destinationViewController as! DropdownViewController + dropdownVC = segue.destination as! DropdownViewController - dropdownVC.modalPresentationStyle = .Custom + dropdownVC.modalPresentationStyle = .custom dropdownVC.transitioningDelegate = dropdownTransitioningDelegate dropdownVC.dropdownPressed = {(index: Int) -> Void in @@ -80,7 +80,7 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon hiddenStatusBar = false if segue.identifier == "embedSegue" { - let childViewController = segue.destinationViewController as! DropdownViewController + let childViewController = segue.destination as! DropdownViewController childViewController.delegate = self } } @@ -89,18 +89,18 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon func show(completion: () -> Void) { dropdownButtonImage.animationImages = self.animationImages; - dropdownButtonImage.image = dropdownButtonImage.animationImages?.last as? UIImage + dropdownButtonImage.image = dropdownButtonImage.animationImages?.last dropdownButtonImage.startAnimating() let delay = dropdownButtonImage.animationDuration * Double(NSEC_PER_SEC) - var time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) - dispatch_after(time, dispatch_get_main_queue(), { () -> Void in + let time = DispatchTime.now() + delay + DispatchQueue.main.asyncAfter(deadline: time, execute: { () -> Void in self.dropdownButtonImage.stopAnimating() }) - var animationDuration = Double(self.animationMultiplier) * 1 / 2.5; + let animationDuration = Double(self.animationMultiplier) * 1 / 2.5; - UIView.animateWithDuration(animationDuration, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, animations: { () -> Void in self.backgroundView.alpha = 1 }) @@ -108,18 +108,18 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon func hide(completion: () -> Void ) { dropdownButtonImage.animationImages = self.reversedAnimationImages - dropdownButtonImage.image = dropdownButtonImage.animationImages?.last as? UIImage + dropdownButtonImage.image = dropdownButtonImage.animationImages?.last dropdownButtonImage.startAnimating() let delay = dropdownButtonImage.animationDuration * Double(NSEC_PER_SEC) - var time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) - dispatch_after(time, dispatch_get_main_queue(), { () -> Void in + let time = DispatchTime.now() + delay + DispatchQueue.main.asyncAfter(deadline: time, execute: { () -> Void in self.dropdownButtonImage.stopAnimating() }) - var animationDuration = Double(self.animationMultiplier) * 1 / 2.5; + let animationDuration = Double(self.animationMultiplier) * 1 / 2.5; - UIView.animateWithDuration(animationDuration, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, animations: { () -> Void in self.backgroundView.alpha = 0 }) @@ -127,19 +127,19 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon // MARK: - Actions - @IBAction func buttonAction(sender: AnyObject) { + @IBAction func buttonAction(_ sender: AnyObject) { dropdownVC.toggle() self.toggle() } func toggle() { if (isOpen) { - hide { () -> () in + hide { false } isOpen = false } else { - show { () -> () in + show { false } isOpen = true @@ -154,16 +154,16 @@ class DropdownExampleViewController: ExampleNobelViewController, DropDownViewCon // MARK: - Appearance - override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation { - return UIStatusBarAnimation.Fade + override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { + return UIStatusBarAnimation.fade } - override func prefersStatusBarHidden() -> Bool { + override var prefersStatusBarHidden: Bool { return hiddenStatusBar } - override func preferredStatusBarStyle() -> UIStatusBarStyle { - return UIStatusBarStyle.LightContent + override var preferredStatusBarStyle: UIStatusBarStyle { + return UIStatusBarStyle.lightContent } diff --git a/Animation/Dropdown/DropdownViewController.swift b/Animation/Dropdown/DropdownViewController.swift index 2d94173..93aca2e 100644 --- a/Animation/Dropdown/DropdownViewController.swift +++ b/Animation/Dropdown/DropdownViewController.swift @@ -57,9 +57,9 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi ]; var delegate:DropDownViewControllerDelegate? - var reversedAnimationImages: [UIImage] { get { return reverse(animationImages) } } + var reversedAnimationImages: [UIImage] { get { return animationImages.reversed() } } var tableHeight: CGFloat { get { return CGFloat(cellHeight * numberOfCells) } } - var dropdownPressed: ((index: Int) -> Void)? + var dropdownPressed: ((_ index: Int) -> Void)? var isOpen = false // MARK: - Lifecycle @@ -67,9 +67,9 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi override func viewDidLoad() { super.viewDidLoad() - menuBackgroundWidth.constant = UIScreen.mainScreen().bounds.size.width - optionsTop.constant = -UIScreen.mainScreen().bounds.size.height - optionsBottom.constant = UIScreen.mainScreen().bounds.size.height + menuBackgroundWidth.constant = UIScreen.main.bounds.size.width + optionsTop.constant = -UIScreen.main.bounds.size.height + optionsBottom.constant = UIScreen.main.bounds.size.height } @@ -79,18 +79,18 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi let animationDuration = Double(self.animationMultiplier) * 1 / 2.5 var dropdownBottom: CGFloat - if tableHeight < UIScreen.mainScreen().bounds.size.height { + if tableHeight < UIScreen.main.bounds.size.height { dropdownBottom = - UIScreen.mainScreen().bounds.size.height - tableHeight - separatorView.bounds.height + UIScreen.main.bounds.size.height - tableHeight - separatorView.bounds.height } else { dropdownBottom = 10 } let easing = LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0) - LayoutConstraintAnimator(constraint: self.optionsTop, delay: 0, + _ = LayoutConstraintAnimator(constraint: self.optionsTop, delay: 0, duration: animationDuration, toConstant: CGFloat(0), easing: easing, completion: nil) - LayoutConstraintAnimator(constraint: self.optionsBottom, delay: 0, + _ = LayoutConstraintAnimator(constraint: self.optionsBottom, delay: 0, duration: animationDuration, toConstant: dropdownBottom, easing: easing, completion: nil) } @@ -98,21 +98,21 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi func hide(completion: (() -> Void)?) { let animationDuration = Double(self.animationMultiplier) * 1 / 2.5 let easing = LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0) - let constant = UIScreen.mainScreen().bounds.size.height + let constant = UIScreen.main.bounds.size.height - LayoutConstraintAnimator(constraint: self.optionsTop, delay: 0, + _ = LayoutConstraintAnimator(constraint: self.optionsTop, delay: 0, duration: animationDuration, toConstant: -constant, easing: easing, completion: nil) - LayoutConstraintAnimator(constraint: self.optionsBottom, delay: 0, + _ = LayoutConstraintAnimator(constraint: self.optionsBottom, delay: 0, duration: animationDuration, toConstant: constant, easing: easing, completion: nil) } func toggle() { if (isOpen) { - self.hide(nil) + self.hide(completion: nil) } else { - self.show(nil) + self.show(completion: nil) } isOpen = !isOpen @@ -120,13 +120,13 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi // MARK: - Table View - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return numberOfCells } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - var cell = tableView.dequeueReusableCellWithIdentifier("DropdownOptionCell") as! DropdownOptionCell + let cell = tableView.dequeueReusableCell(withIdentifier: "DropdownOptionCell") as! DropdownOptionCell cell.label.text = "Option \(indexPath.row + 1)" @@ -144,15 +144,15 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi return cell; } - func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { - tableView.deselectRowAtIndexPath(indexPath, animated: true) + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath as IndexPath, animated: true) self.toggle() - self.delegate?.dropDownViewControllerDidPressButton(self) + self.delegate?.dropDownViewControllerDidPressButton(viewController: self) } // MARK: - Appearance - override func prefersStatusBarHidden() -> Bool { + override var prefersStatusBarHidden: Bool { return true } diff --git a/Animation/ExampleNobelViewController.swift b/Animation/ExampleNobelViewController.swift index 16e2463..05851e1 100644 --- a/Animation/ExampleNobelViewController.swift +++ b/Animation/ExampleNobelViewController.swift @@ -20,10 +20,10 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab // MARK: - Constants, Properties - var nobelsAlphabetically: NSArray? - var nobelsByDiscipline: NSArray? - var nobels: NSArray? - var filteredNobels: NSMutableArray? + var nobelsAlphabetically: [Any]? + var nobelsByDiscipline: [Any]? + var nobels: [Any]? + var filteredNobels: [Any]? var filters: [Bool] = [] // MARK: - Lifecycle @@ -35,20 +35,29 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab } func loadData() { - let bundle = NSBundle.mainBundle() - var error:NSError? + let bundle = Bundle.main - let path1 = bundle.pathForResource("nobels_alphabetically", ofType: "json") - var data1:NSData = NSData(contentsOfFile: path1!)! - let json1:AnyObject = NSJSONSerialization.JSONObjectWithData(data1, options: NSJSONReadingOptions.AllowFragments, error:&error)! + let path1 = bundle.path(forResource: "nobels_alphabetically", ofType: "json") + let data1:NSData = NSData(contentsOfFile: path1!)! + var json1: Any = [] + do { + json1 = try JSONSerialization.jsonObject(with: data1 as Data, options: JSONSerialization.ReadingOptions.allowFragments) + } catch { + print("nobels_alphabetically.json could not be read") + } - nobelsAlphabetically = json1 as? NSArray + nobelsAlphabetically = json1 as? [Any] - let path2 = bundle.pathForResource("nobels_by_discipline", ofType: "json") - var data2:NSData = NSData(contentsOfFile: path2!)! - let json2:AnyObject = NSJSONSerialization.JSONObjectWithData(data2, options: NSJSONReadingOptions.AllowFragments, error:&error)! + let path2 = bundle.path(forResource: "nobels_by_discipline", ofType: "json") + let data2:NSData = NSData(contentsOfFile: path2!)! + var json2: Any = [] + do { + json2 = try JSONSerialization.jsonObject(with: data2 as Data, options: JSONSerialization.ReadingOptions.allowFragments) + } catch { + print("nobels_by_discipline could not be read") + } - nobelsByDiscipline = json2 as? NSArray + nobelsByDiscipline = json2 as? [Any] filters = [true, true, true, true] @@ -69,55 +78,44 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab func updateFilters() { - filteredNobels = NSMutableArray() + filteredNobels = [] if let nobels = nobels { - for index in 0...nobels.count - 1 { - - if let section = nobels.objectAtIndex(index) as? NSDictionary { - - let array = section["Data"] as? NSArray - - var nobel_dict = NSMutableDictionary() + if let section = nobels[index] as? [String: Any] { + let array = section["Data"] as? [Any] + var nobel_dict: [String: Any] = [:] nobel_dict["Section"] = section["Section"] - var nobel_array = NSMutableArray() - + var nobel_array: [Any] = [] if let array = array { - for nobel_index in 0...array.count - 1 { - let person_dict = array[nobel_index] as? NSDictionary - if let person_dict = person_dict { - let discipline = person_dict["Discipline"] as? String if let discipline = discipline { if filters[0] && discipline == "Chemistry" { - nobel_array.addObject(array[nobel_index]) + nobel_array.append(array[nobel_index]) } else if filters[1] && discipline == "Economics" { - nobel_array.addObject(array[nobel_index]) + nobel_array.append(array[nobel_index]) } else if filters[2] && discipline == "Literature" { - nobel_array.addObject(array[nobel_index]) + nobel_array.append(array[nobel_index]) } else if filters[3] && discipline == "Medicine" { - nobel_array.addObject(array[nobel_index]) + nobel_array.append(array[nobel_index]) } } } - } - } nobel_dict["Data"] = nobel_array - filteredNobels?.addObject(nobel_dict) + filteredNobels?.append(nobel_dict) } } @@ -136,21 +134,25 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab } } - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if let nobels = filteredNobels { - return (nobels[section]["Data"] as! NSArray).count + let nobelsInSection = nobels[section] as! [String: Any] + let nobelData = nobelsInSection["Data"] as! [Any] + return nobelData.count } else { return 0 } } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let table = tableView as! TableView - let cell = tableView.dequeueReusableCellWithIdentifier(table.cellID, forIndexPath: indexPath) as! TableViewCell + let cell = tableView.dequeueReusableCell(withIdentifier: table.cellID, for: indexPath as IndexPath) as! TableViewCell if let nobels = filteredNobels { - let person = (nobels[indexPath.section]["Data"] as! NSArray)[indexPath.row] as? NSDictionary - if let person = person { + //let person = (nobels[indexPath.section]["Data"][indexPath.row] as? NSDictionary + let nobelsInSection = nobels[indexPath.section] as! [String: Any] + let nobelData = nobelsInSection["Data"] as! [Any] + if let person = nobelData[indexPath.row] as? [String: Any] { let lastName = person["Last name"] as! String let firstName = person["First name"] as! String @@ -162,30 +164,31 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab } } - cell.selectionStyle = UITableViewCellSelectionStyle.None + cell.selectionStyle = UITableViewCellSelectionStyle.none return cell } - func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int { + func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { return index } - func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - let cell = tableView.dequeueReusableCellWithIdentifier("TableViewHeaderCellID") as! TableViewHeaderCell + let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewHeaderCellID") as! TableViewHeaderCell if let nobels = filteredNobels { - cell.label.text = nobels[section]["Section"] as? String + let nobelsInSection = nobels[section] as! [String: Any] + cell.label.text = nobelsInSection["Section"] as? String } return cell } - func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 50 } - func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 80 } } diff --git a/Animation/Images.xcassets/AppIcon.appiconset/Contents.json b/Animation/Images.xcassets/AppIcon.appiconset/Contents.json index 40bbadd..fae0dd7 100644 --- a/Animation/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Animation/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -32,6 +42,16 @@ "filename" : "Motion_icon180.png", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -61,6 +81,16 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Animation/LayoutConstraintAnimator.swift b/Animation/LayoutConstraintAnimator.swift index 1c06e3b..a84dbed 100644 --- a/Animation/LayoutConstraintAnimator.swift +++ b/Animation/LayoutConstraintAnimator.swift @@ -15,7 +15,7 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac class LayoutConstraintAnimator: NSObject { - internal lazy var link: CADisplayLink = CADisplayLink(target: self, selector: Selector("timer")) + internal lazy var link: CADisplayLink = CADisplayLink(target: self, selector: #selector(LayoutConstraintAnimator.timer)) internal var startTime: Double internal var fromConstants: [CGFloat] internal var delaying: Bool @@ -31,8 +31,8 @@ class LayoutConstraintAnimator: NSObject { Convenience constructor for the animation. Simply wraps the constraint and toConstant in an array for the main constructor. */ - convenience init(constraint: NSLayoutConstraint, delay:NSTimeInterval, - duration:NSTimeInterval, toConstant:CGFloat, easing: LayoutConstraintEasing, + convenience init(constraint: NSLayoutConstraint, delay:TimeInterval, + duration:TimeInterval, toConstant:CGFloat, easing: LayoutConstraintEasing, completion: (() -> Void)?) { self.init( @@ -52,8 +52,8 @@ class LayoutConstraintAnimator: NSObject { :param: easing The easing algorithm to be used when calculating the target's values :param: completion The block to be performed on completion of the animation */ - required init(constraints: [NSLayoutConstraint], delay:NSTimeInterval, - duration:NSTimeInterval, toConstants:[CGFloat], easing: LayoutConstraintEasing, + required init(constraints: [NSLayoutConstraint], delay:TimeInterval, + duration:TimeInterval, toConstants:[CGFloat], easing: LayoutConstraintEasing, completion: (() -> Void)?) { self.constraints = constraints @@ -73,10 +73,10 @@ class LayoutConstraintAnimator: NSObject { super.init() - self.link.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes) + self.link.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) } - internal func timer() { + @objc internal func timer() { // checks to see if we should continue delaying or process the animation if delaying { if (CACurrentMediaTime() - startTime) >= delay { @@ -87,16 +87,16 @@ class LayoutConstraintAnimator: NSObject { } } - var time = CGFloat((CACurrentMediaTime() - startTime) / duration) + let time = CGFloat((CACurrentMediaTime() - startTime) / duration) // check to see if the animation has completed if time >= 1 { - for (index, constraint) in enumerate(constraints) { + for (index, constraint) in constraints.enumerated() { constraint.constant = toConstants[index] } link.invalidate() - link.removeFromRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes) + link.remove(from: RunLoop.main, forMode: RunLoopMode.commonModes) if let completion = completion { completion() @@ -106,10 +106,10 @@ class LayoutConstraintAnimator: NSObject { } // process the animation - var t = easing.valueFor(CGFloat(time)) + let t = easing.valueFor(t: CGFloat(time)) - for (index, constraint) in enumerate(constraints) { + for (index, constraint) in constraints.enumerated() { constraint.constant = (1 - t) * fromConstants[index] + t * toConstants[index] } } -} \ No newline at end of file +} diff --git a/Animation/LayoutConstraintEasing.swift b/Animation/LayoutConstraintEasing.swift index 37fae8f..fdc409f 100644 --- a/Animation/LayoutConstraintEasing.swift +++ b/Animation/LayoutConstraintEasing.swift @@ -19,12 +19,12 @@ enum LayoutConstraintEasing { func valueFor(t: CGFloat) -> CGFloat { switch (self) { - case let .Linear: return t - case let .Bezier(x1, y1, x2, y2): return bezier(t, x1:x1, y1:y1, x2:x2, y2:y2) + case .Linear: return t + case .Bezier(let x1, let y1, let x2, let y2): return bezier(t: t, x1:x1, y1:y1, x2:x2, y2:y2) - case let .EaseInOut: return bezier(t, x1:easeInOutControlPoints[0], y1:easeInOutControlPoints[1], x2:easeInOutControlPoints[2], y2:easeInOutControlPoints[3]) - case let .EaseIn: return bezier(t, x1:easeInOutControlPoints[1], y1:easeInOutControlPoints[0], x2:easeInOutControlPoints[2], y2:easeInOutControlPoints[3]) - case let .EaseOut: return bezier(t, x1:easeInOutControlPoints[0], y1:easeInOutControlPoints[1], x2:easeInOutControlPoints[3], y2:easeInOutControlPoints[2]) + case .EaseInOut: return bezier(t: t, x1:easeInOutControlPoints[0], y1:easeInOutControlPoints[1], x2:easeInOutControlPoints[2], y2:easeInOutControlPoints[3]) + case .EaseIn: return bezier(t: t, x1:easeInOutControlPoints[1], y1:easeInOutControlPoints[0], x2:easeInOutControlPoints[2], y2:easeInOutControlPoints[3]) + case .EaseOut: return bezier(t: t, x1:easeInOutControlPoints[0], y1:easeInOutControlPoints[1], x2:easeInOutControlPoints[3], y2:easeInOutControlPoints[2]) } } @@ -32,13 +32,13 @@ enum LayoutConstraintEasing { // Simple linear interpolation between two points func lerp(a:CGPoint, b:CGPoint, t:CGFloat) -> CGPoint { - return CGPointMake(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); + return CGPoint(x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t); } func bezier(t: CGFloat, x1:CGFloat, y1:CGFloat, x2:CGFloat, y2:CGFloat) -> CGFloat { let cubicBezier = CubicBezier(x1: x1, y1: y1, x2: x2, y2: y2) - return cubicBezier.valueForX(t) + return cubicBezier.valueForX(x: t) } static var EaseInOutMTF : CAMediaTimingFunction { @@ -59,4 +59,4 @@ enum LayoutConstraintEasing { } -} \ No newline at end of file +} diff --git a/Animation/MainNavigationViewController.swift b/Animation/MainNavigationViewController.swift index 1aa4446..8c8d4e3 100644 --- a/Animation/MainNavigationViewController.swift +++ b/Animation/MainNavigationViewController.swift @@ -15,20 +15,20 @@ class MainNavigationViewController: UINavigationController { // MARK: - Lifecycle - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // Create a long press recognizer that requires two fingers and reverts the navigation back to the // main menu. - var longPressRecognizer = UILongPressGestureRecognizer(target: self, action: Selector("longPress:")) + let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(MainNavigationViewController.longPress(_:))) longPressRecognizer.numberOfTouchesRequired = 2 view.addGestureRecognizer(longPressRecognizer) } // MARK: - Flow - func longPress(longPress: UILongPressGestureRecognizer) { - popToRootViewControllerAnimated(true) + @objc func longPress(_ longPress: UILongPressGestureRecognizer) { + _ = popToRootViewController(animated: true) } } diff --git a/Animation/MainViewController.swift b/Animation/MainViewController.swift index 9cbe8d1..5499446 100644 --- a/Animation/MainViewController.swift +++ b/Animation/MainViewController.swift @@ -35,18 +35,18 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat // MARK: - Scroll View - func scrollViewDidScroll(scrollView: UIScrollView) { + func scrollViewDidScroll(_ scrollView: UIScrollView) { let scrollOffset = scrollView.contentOffset.y - let maxScrollOffset: CGFloat = 30 - let alphaPercentage = (150 - (scrollOffset * 10)) / 150 * 2 + let _: CGFloat = 30 + _ = (150 - (scrollOffset * 10)) / 150 * 2 if noteViewHeight == nil { noteViewHeight = noteViewHeightConstraint.constant } - let offsetToShowNote: CGFloat = -20 - let offsetToHideNote: CGFloat = 15 + let _: CGFloat = -20 + let _: CGFloat = 15 } // MARK: - Table View @@ -55,7 +55,7 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat return 1 } - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { case 0: return 4 @@ -64,9 +64,9 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat } } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCellID") as! TableViewCell - cell.backgroundColor = UIColor.clearColor() + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCellID") as! TableViewCell + cell.backgroundColor = UIColor.clear // Display text switch (indexPath.section, indexPath.row) { @@ -85,24 +85,24 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat return cell } - func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 50 } - func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { // Row selected, view storyboard by ID switch (indexPath.section, indexPath.row) { case (0, 0): - showView("TabBar", viewControllerID: "TabBarControllerID") + showView(storyboard: "TabBar", viewControllerID: "TabBarControllerID") case (0, 1): - showView("Search", viewControllerID: "SearchNavigationControllerID") + showView(storyboard: "Search", viewControllerID: "SearchNavigationControllerID") case (0, 2): - showView("Modal", viewControllerID: "ModalNavigationControllerID") + showView(storyboard: "Modal", viewControllerID: "ModalNavigationControllerID") case (0, 3): - showView("Dropdown", viewControllerID: "DropdownViewControllerID") + showView(storyboard: "Dropdown", viewControllerID: "DropdownViewControllerID") default:break } - tableView.deselectRowAtIndexPath(indexPath, animated: false) + tableView.deselectRow(at: indexPath as IndexPath, animated: false) } // MARK: - Flow @@ -111,11 +111,11 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat // navigation controller. func showView(storyboard: String, viewControllerID: String) { let sb = UIStoryboard(name: storyboard, bundle: nil) - let vc = sb.instantiateViewControllerWithIdentifier(viewControllerID) as! UIViewController + let vc = sb.instantiateViewController(withIdentifier: viewControllerID) if vc is UINavigationController { - var nav = vc as! UINavigationController - var view = nav.viewControllers.first as! UIViewController + let nav = vc as! UINavigationController + let view = nav.viewControllers.first! self.navigationController?.pushViewController(view, animated: true) } else { self.navigationController?.pushViewController(vc, animated: true) @@ -125,8 +125,8 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat // MARK: - Appearance - override func preferredStatusBarStyle() -> UIStatusBarStyle { - return UIStatusBarStyle.LightContent + override var preferredStatusBarStyle: UIStatusBarStyle { + return UIStatusBarStyle.lightContent } } diff --git a/Animation/Modal/Modal.storyboard b/Animation/Modal/Modal.storyboard index 4038686..cf3d97f 100644 --- a/Animation/Modal/Modal.storyboard +++ b/Animation/Modal/Modal.storyboard @@ -1,20 +1,27 @@ - - + + + + + - + + + + + HelveticaNeue-Light + + - - @@ -48,7 +55,7 @@ - + @@ -68,7 +75,7 @@ @@ -774,11 +780,11 @@ - + @@ -790,14 +796,14 @@ - + - + - + @@ -819,7 +825,7 @@ - + @@ -838,7 +844,7 @@ - + @@ -849,7 +855,7 @@ - + @@ -867,7 +873,6 @@ - @@ -889,7 +894,7 @@ - + diff --git a/Animation/Modal/ModalAppearTransitioning.swift b/Animation/Modal/ModalAppearTransitioning.swift index 206da82..3f61a08 100644 --- a/Animation/Modal/ModalAppearTransitioning.swift +++ b/Animation/Modal/ModalAppearTransitioning.swift @@ -8,21 +8,21 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac class ModalAppearTransitioning: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.8 } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { - let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! ModalViewController + let to = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as! ModalViewController - let container = transitionContext.containerView() - let duration = transitionDuration(transitionContext) + let container = transitionContext.containerView + let duration = transitionDuration(using: transitionContext) container.addSubview(to.view) to.show() { - transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) + transitionContext.completeTransition(!transitionContext.transitionWasCancelled) } } diff --git a/Animation/Modal/ModalDismissTransitioning.swift b/Animation/Modal/ModalDismissTransitioning.swift index 33b9d7a..a5e0b46 100644 --- a/Animation/Modal/ModalDismissTransitioning.swift +++ b/Animation/Modal/ModalDismissTransitioning.swift @@ -8,28 +8,28 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac class ModalDismissTransitioning: NSObject, UIViewControllerAnimatedTransitioning { - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.8 } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { - let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! - let from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as! ModalViewController + let to = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! + let from = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as! ModalViewController - let container = transitionContext.containerView() - let duration = transitionDuration(transitionContext) + let container = transitionContext.containerView + _ = transitionDuration(using: transitionContext) - container.insertSubview(to.view, atIndex: 0) + container.insertSubview(to.view, at: 0) from.hide() { - transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) + transitionContext.completeTransition(!transitionContext.transitionWasCancelled) // Because the From View Controller disappears using UIViewControllerContextTransitioning, // re-add the toViewController's view as a subview of the key window's. // This is a solution for an iOS 8 bug. For details, see: // http://stackoverflow.com/questions/24338700/from-view-controller-disappears-using-uiviewcontrollercontexttransitioning - UIApplication.sharedApplication().keyWindow!.addSubview(to.view) + UIApplication.shared.keyWindow!.addSubview(to.view) } } diff --git a/Animation/Modal/ModalExampleViewController.swift b/Animation/Modal/ModalExampleViewController.swift index 2439b51..442d46b 100644 --- a/Animation/Modal/ModalExampleViewController.swift +++ b/Animation/Modal/ModalExampleViewController.swift @@ -34,9 +34,9 @@ class ModalExampleViewController: ExampleNobelViewController { // MARK: - Lifecycle - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - var modalVC = segue.destinationViewController as! ModalViewController - modalVC.modalPresentationStyle = .Custom + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + let modalVC = segue.destination as! ModalViewController + modalVC.modalPresentationStyle = .custom modalVC.transitioningDelegate = modalTransitioningDelegate hiddenStatusBar = false @@ -44,15 +44,15 @@ class ModalExampleViewController: ExampleNobelViewController { // MARK: - Appearance - override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation { - return UIStatusBarAnimation.Fade + override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { + return UIStatusBarAnimation.fade } - override func prefersStatusBarHidden() -> Bool { + override var prefersStatusBarHidden: Bool { return hiddenStatusBar } - override func preferredStatusBarStyle() -> UIStatusBarStyle { - return UIStatusBarStyle.LightContent + override var preferredStatusBarStyle: UIStatusBarStyle { + return UIStatusBarStyle.lightContent } } diff --git a/Animation/Modal/ModalViewController.swift b/Animation/Modal/ModalViewController.swift index f186be6..93a2e23 100644 --- a/Animation/Modal/ModalViewController.swift +++ b/Animation/Modal/ModalViewController.swift @@ -36,7 +36,7 @@ class ModalViewController: UIViewController, UITableViewDelegate { // MARK: - Constants, Properties - var modalPressed: ((index: Int) -> Void)? + var modalPressed: ((_ index: Int) -> Void)? let animationMultiplier : CGFloat = 1 let maxModalHeadHeight: CGFloat = 80 @@ -47,14 +47,14 @@ class ModalViewController: UIViewController, UITableViewDelegate { super.viewDidLoad() modalHeadHeight.constant = modalHead.bounds.size.height - modalBackgroundTop.constant = UIScreen.mainScreen().bounds.size.height - 50 + modalBackgroundTop.constant = UIScreen.main.bounds.size.height - 50 self.pdfView.alpha = 0 loader.animationImages = [UIImage]() - for var index = 100; index < 147; index++ { - var frameName = String(format: "Loader_00%03d", index) + for index in 100..<147 { + let frameName = String(format: "Loader_00%03d", index) loader.animationImages?.append(UIImage(named:frameName)!) } @@ -67,7 +67,7 @@ class ModalViewController: UIViewController, UITableViewDelegate { // MARK: - Scroll View // header shrinks and its elements resize based on scroll position - func scrollViewDidScroll(scrollView: UIScrollView) { + func scrollViewDidScroll(_ scrollView: UIScrollView) { // update views based on scroll offset let scrollOffset = scrollView.contentOffset.y @@ -83,11 +83,11 @@ class ModalViewController: UIViewController, UITableViewDelegate { if (scrollOffset < 0) { // at top // set to max position - self.menuLabel.transform = CGAffineTransformIdentity + self.menuLabel.transform = CGAffineTransform.identity self.buttonImageView.alpha = 1 - self.closeButton.enabled = true + self.closeButton.isEnabled = true - UIView.animateWithDuration(0.1, animations: { + UIView.animate(withDuration: 0.1, animations: { self.modalHeadHeight.constant = 80 self.view.layoutIfNeeded() }) @@ -96,11 +96,11 @@ class ModalViewController: UIViewController, UITableViewDelegate { // proportionally adjust the header and it's children if scrollOffset < maxScrollOffset { self.buttonImageView.alpha = scalePercent - self.closeButton.enabled = true - self.menuLabel.transform = CGAffineTransformMakeScale(labelEndPercent, labelEndPercent) - self.buttonImageView.transform = CGAffineTransformMakeScale(labelEndPercent, labelEndPercent) + self.closeButton.isEnabled = true + self.menuLabel.transform = CGAffineTransform(scaleX: labelEndPercent, y: labelEndPercent) + self.buttonImageView.transform = CGAffineTransform(scaleX: labelEndPercent, y: labelEndPercent) - UIView.animateWithDuration(0.1, animations: { + UIView.animate(withDuration: 0.1, animations: { self.modalHeadHeight.constant = (80 - scrollOffset) self.view.layoutIfNeeded() }) @@ -108,10 +108,10 @@ class ModalViewController: UIViewController, UITableViewDelegate { // scrolled beyond minimun // set to min position self.buttonImageView.alpha = 0 - self.closeButton.enabled = false - self.menuLabel.transform = CGAffineTransformMakeScale((self.modalHead.bounds.height / maxModalHeadHeight) + 0.15, (self.modalHead.bounds.height / maxModalHeadHeight) + 0.2) + self.closeButton.isEnabled = false + self.menuLabel.transform = CGAffineTransform(scaleX: (self.modalHead.bounds.height / maxModalHeadHeight) + 0.15, y: (self.modalHead.bounds.height / maxModalHeadHeight) + 0.2) - UIView.animateWithDuration(0.1, animations: { + UIView.animate(withDuration: 0.1, animations: { self.modalHeadHeight.constant = 40 self.view.layoutIfNeeded() }) @@ -121,35 +121,35 @@ class ModalViewController: UIViewController, UITableViewDelegate { // MARK: - Transition Animations - func show(completion: () -> Void ) { + func show(completion: @escaping () -> Void ) { - var animationDuration = Double(self.animationMultiplier) * 1 / 3.0; + let animationDuration = Double(self.animationMultiplier) * 1 / 3.0; backgroundView.alpha = 0 loaderBG.alpha = 1 loader.alpha = 1 - UIView.animateWithDuration(animationDuration, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, animations: { () -> Void in self.backgroundView.alpha = 1 }, completion: { finished in // display PDF // first string value is pdf file name - var pdfLoc = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("Bee", ofType:"pdf")!) - var request = NSURLRequest(URL: pdfLoc!); - self.pdfView.loadRequest(request); + let pdfLoc = NSURL(fileURLWithPath:Bundle.main.path(forResource: "Bee", ofType:"pdf")!) + let request = NSURLRequest(url: pdfLoc as URL); + self.pdfView.loadRequest(request as URLRequest); self.pdfView.alpha = 0 - self.pdfView.transform = CGAffineTransformMakeScale(0.75, 0.75) + self.pdfView.transform = CGAffineTransform(scaleX: 0.75, y: 0.75) // show PDF - UIView.animateWithDuration(animationDuration, delay: 1.5, options: nil, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, delay: 1.5, options: [], animations: { () -> Void in self.loader.alpha = 0 // fade out loader }, completion: { finished in - UIView.animateWithDuration(0.25, delay: 0, options: nil, animations: { () -> Void in + UIView.animate(withDuration: 0.25, delay: 0, options: [], animations: { () -> Void in // fade in PDF self.loaderBG.alpha = 0 self.pdfView.alpha = 1 - self.pdfView.transform = CGAffineTransformIdentity + self.pdfView.transform = CGAffineTransform.identity }, completion: { finished in }) @@ -157,41 +157,41 @@ class ModalViewController: UIViewController, UITableViewDelegate { }) - var timer = LayoutConstraintAnimator(constraint: self.modalBackgroundTop, delay: 0, duration: animationDuration, toConstant: CGFloat(0), easing: LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0), completion: completion) + _ = LayoutConstraintAnimator(constraint: self.modalBackgroundTop, delay: 0, duration: animationDuration, toConstant: CGFloat(0), easing: LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0), completion: completion) } - func hide(completion: () -> Void ) { + func hide(completion: @escaping () -> Void ) { - var animationDuration = Double(self.animationMultiplier) * 1 / 4.0; + let animationDuration = Double(self.animationMultiplier) * 1 / 4.0; self.view.layoutIfNeeded() - UIView.animateWithDuration(animationDuration, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, animations: { () -> Void in self.backgroundView.alpha = 0 }) - var timer = LayoutConstraintAnimator(constraint: self.modalBackgroundTop, delay: 0, duration: animationDuration, toConstant: (UIScreen.mainScreen().bounds.size.height + 10), easing: LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0)) { finished in + _ = LayoutConstraintAnimator(constraint: self.modalBackgroundTop, delay: 0, duration: animationDuration, toConstant: (UIScreen.main.bounds.size.height + 100), easing: LayoutConstraintEasing.Bezier(x1: 0.5, y1: 0.08, x2: 0.0, y2: 1.0)) { - self.modalPressed?(index:0) + self.modalPressed?(0) completion() } } // MARK: - Actions - @IBAction func hideAction(sender: AnyObject) { - closeButton.hidden = true - dismissViewControllerAnimated(true, completion: nil) + @IBAction func hideAction(_ sender: AnyObject) { + closeButton.isHidden = true + dismiss(animated: true, completion: nil) } // MARK: - Appearance - override func prefersStatusBarHidden() -> Bool { + override var prefersStatusBarHidden: Bool { return false } - override func preferredStatusBarStyle() -> UIStatusBarStyle { - return UIStatusBarStyle.LightContent + override var preferredStatusBarStyle: UIStatusBarStyle { + return UIStatusBarStyle.lightContent } } diff --git a/Animation/Other/Button.swift b/Animation/Other/Button.swift index 7ab9442..c686f03 100644 --- a/Animation/Other/Button.swift +++ b/Animation/Other/Button.swift @@ -10,7 +10,7 @@ class Button: UIButton { override func awakeFromNib() { super.awakeFromNib() - setTitleColor(MotionStyleKit.motion_Color, forState: .Normal) + setTitleColor(MotionStyleKit.motion_Color, for: []) } } diff --git a/Animation/Other/View.swift b/Animation/Other/View.swift index 38290a9..420edd0 100644 --- a/Animation/Other/View.swift +++ b/Animation/Other/View.swift @@ -13,7 +13,7 @@ This licensed material is licensed under the Apache 2.0 license. http://www.apac backgroundColor = MotionStyleKit.motion_Color } - override func drawRect(rect: CGRect) { + override func draw(_ rect: CGRect) { let rectanglePath = UIBezierPath(rect: rect) backgroundColor?.setFill() rectanglePath.fill() diff --git a/Animation/Search/Search.storyboard b/Animation/Search/Search.storyboard index eb80aaf..83e720b 100644 --- a/Animation/Search/Search.storyboard +++ b/Animation/Search/Search.storyboard @@ -1,11 +1,23 @@ - - + + + + + - + + + + + HelveticaNeue-Bold + + + HelveticaNeue-Light + + @@ -29,7 +41,7 @@ - + @@ -47,7 +59,7 @@ - + @@ -59,7 +71,7 @@ @@ -75,11 +87,11 @@ - + - + @@ -89,11 +101,11 @@ - + @@ -125,11 +137,11 @@ - + - + @@ -139,11 +151,11 @@ - + @@ -175,11 +187,11 @@ - + - + @@ -189,11 +201,11 @@ - + @@ -225,11 +237,11 @@ - + - + @@ -239,11 +251,11 @@ - + @@ -275,11 +287,11 @@ - + - + @@ -289,11 +301,11 @@ - + @@ -325,11 +337,11 @@ - + - + @@ -339,11 +351,11 @@ - + @@ -445,14 +457,14 @@ - + - + @@ -477,7 +489,7 @@ - + @@ -486,7 +498,7 @@ @@ -502,11 +514,11 @@ - + - + @@ -516,11 +528,11 @@ - + @@ -541,8 +553,9 @@ @@ -564,25 +577,25 @@ - + - + -