Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Swift2.0 #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Pods/
Carthage/Checkouts

Carthage/Build
contents.xcworkspacedata
2 changes: 2 additions & 0 deletions Animation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@
80C472FE19DDC6C2008274C0 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = IBM;
TargetAttributes = {
Expand Down
5 changes: 3 additions & 2 deletions Animation/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="l7B-OX-K3o">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="l7B-OX-K3o">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down
4 changes: 2 additions & 2 deletions Animation/Dropdown/DropdownAppearTransitioning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.8
}

Expand All @@ -19,7 +19,7 @@ class DropdownAppearTransitioning: NSObject, UIViewControllerAnimatedTransitioni
let container = transitionContext.containerView()
let duration = transitionDuration(transitionContext)

container.addSubview(to.view)
container!.addSubview(to.view)

to.show() {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
Expand Down
4 changes: 2 additions & 2 deletions Animation/Dropdown/DropdownDismissTransitioning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.8
}

Expand All @@ -20,7 +20,7 @@ class DropdownDismissTransitioning: NSObject, UIViewControllerAnimatedTransition
let container = transitionContext.containerView()
let duration = transitionDuration(transitionContext)

container.insertSubview(to.view, atIndex: 0)
container!.insertSubview(to.view, atIndex: 0)

from.hide() {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
Expand Down
14 changes: 7 additions & 7 deletions Animation/Dropdown/DropdownExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 Array(animationImages.reverse()) } }

var hiddenStatusBar:Bool = false {
didSet {
Expand Down Expand Up @@ -89,16 +89,16 @@ 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))
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), { () -> 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
self.backgroundView.alpha = 1
Expand All @@ -108,16 +108,16 @@ 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))
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), { () -> 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
self.backgroundView.alpha = 0
Expand Down
4 changes: 2 additions & 2 deletions Animation/Dropdown/DropdownViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi
];

var delegate:DropDownViewControllerDelegate?
var reversedAnimationImages: [UIImage] { get { return reverse(animationImages) } }
var reversedAnimationImages: [UIImage] { get { return Array(animationImages.reverse()) } }
var tableHeight: CGFloat { get { return CGFloat(cellHeight * numberOfCells) } }
var dropdownPressed: ((index: Int) -> Void)?
var isOpen = false
Expand Down Expand Up @@ -126,7 +126,7 @@ class DropdownViewController: UIViewController, UITableViewDataSource, UITableVi

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

var cell = tableView.dequeueReusableCellWithIdentifier("DropdownOptionCell") as! DropdownOptionCell
let cell = tableView.dequeueReusableCellWithIdentifier("DropdownOptionCell") as! DropdownOptionCell

cell.label.text = "Option \(indexPath.row + 1)"

Expand Down
12 changes: 6 additions & 6 deletions Animation/ExampleNobelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab
var error:NSError?

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 data1:NSData = NSData(contentsOfFile: path1!)!
let json1:AnyObject = try! NSJSONSerialization.JSONObjectWithData(data1, options: NSJSONReadingOptions.AllowFragments)

nobelsAlphabetically = json1 as? NSArray

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 data2:NSData = NSData(contentsOfFile: path2!)!
let json2:AnyObject = try! NSJSONSerialization.JSONObjectWithData(data2, options: NSJSONReadingOptions.AllowFragments)

nobelsByDiscipline = json2 as? NSArray

Expand Down Expand Up @@ -79,11 +79,11 @@ class ExampleNobelViewController: UIViewController, UITableViewDataSource, UITab

let array = section["Data"] as? NSArray

var nobel_dict = NSMutableDictionary()
let nobel_dict = NSMutableDictionary()

nobel_dict["Section"] = section["Section"]

var nobel_array = NSMutableArray()
let nobel_array = NSMutableArray()

if let array = array {

Expand Down
20 changes: 10 additions & 10 deletions Animation/LayoutConstraintAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class LayoutConstraintAnimator: NSObject {
The constructor for the animation. Once the animation is created, it is not
able to be modified or stopped.

:param: constraints The set of constraints to be animated
:param: delay The delay, in seconds, before beginning the animation
:param: duration The duration, in seconds, of the animation to be performed
:param: toConstants The values of the constants to be set on each of the constraints
: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
- parameter constraints: The set of constraints to be animated
- parameter delay: The delay, in seconds, before beginning the animation
- parameter duration: The duration, in seconds, of the animation to be performed
- parameter toConstants: The values of the constants to be set on each of the constraints
- parameter easing: The easing algorithm to be used when calculating the target's values
- parameter completion: The block to be performed on completion of the animation
*/
required init(constraints: [NSLayoutConstraint], delay:NSTimeInterval,
duration:NSTimeInterval, toConstants:[CGFloat], easing: LayoutConstraintEasing,
Expand Down Expand Up @@ -87,11 +87,11 @@ 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.enumerate() {
constraint.constant = toConstants[index]
}

Expand All @@ -106,9 +106,9 @@ class LayoutConstraintAnimator: NSObject {
}

// process the animation
var t = easing.valueFor(CGFloat(time))
let t = easing.valueFor(CGFloat(time))

for (index, constraint) in enumerate(constraints) {
for (index, constraint) in constraints.enumerate() {
constraint.constant = (1 - t) * fromConstants[index] + t * toConstants[index]
}
}
Expand Down
2 changes: 1 addition & 1 deletion Animation/MainNavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MainNavigationViewController: UINavigationController {

// 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("longPress:"))
longPressRecognizer.numberOfTouchesRequired = 2
view.addGestureRecognizer(longPressRecognizer)
}
Expand Down
11 changes: 7 additions & 4 deletions Animation/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,18 @@ class MainViewController: UIViewController, UIScrollViewDelegate, UITableViewDat
// The view controller is pushed in a different way depending if it's inside a
// 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.instantiateViewControllerWithIdentifier(viewControllerID)

if vc is UINavigationController {
var nav = vc as! UINavigationController
var view = nav.viewControllers.first as! UIViewController
if let nav = vc as? UINavigationController, let view = nav.viewControllers.first {

self.navigationController?.pushViewController(view, animated: true)

} else {

self.navigationController?.pushViewController(vc, animated: true)

}

}
Expand Down
Loading