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

Update to Swift 4 #6

Open
wants to merge 1 commit 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
10 changes: 6 additions & 4 deletions Animation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 22 additions & 12 deletions Animation/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?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">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="l7B-OX-K3o">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="HelveticaNeue.ttc">
<string>HelveticaNeue-Bold</string>
</array>
<array key="HelveticaNeueLights.ttc">
<string>HelveticaNeue-Light</string>
</array>
</customFonts>
<scenes>
<!--Main View Controller-->
<scene sceneID="G2K-IJ-F6u">
Expand All @@ -17,7 +29,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xul-vo-SM5" userLabel="Header View" customClass="View" customModule="Animation" customModuleProvider="target">
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xul-vo-SM5" userLabel="Header View" customClass="View" customModule="Animation" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="80"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="IBM Motion Examples" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="cng-hN-KI8">
Expand All @@ -27,7 +39,7 @@
<constraint firstAttribute="height" constant="28" id="hxl-Yf-RkG"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="22"/>
<color key="textColor" red="0.95686274510000002" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.94598448276519775" green="0.95082128047943115" blue="0.95073151588439941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
Expand All @@ -45,16 +57,16 @@
</mask>
</variation>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" showsSelectionImmediatelyOnTouchBegin="NO" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="pcZ-FJ-beu" userLabel="Table View" customClass="TableView" customModule="Animation" customModuleProvider="target">
<tableView clipsSubviews="YES" contentMode="scaleToFill" misplaced="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="pcZ-FJ-beu" userLabel="Table View" customClass="TableView" customModule="Animation" customModuleProvider="target">
<rect key="frame" x="0.0" y="218" width="375" height="449"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<inset key="separatorInset" minX="16" minY="0.0" maxX="16" maxY="0.0"/>
<connections>
<outlet property="dataSource" destination="KIc-zR-tCS" id="6DR-AX-oxz"/>
<outlet property="delegate" destination="KIc-zR-tCS" id="sph-gK-D0C"/>
</connections>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xPS-X0-YXe" userLabel="Note View" customClass="View" customModule="Animation" customModuleProvider="target">
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xPS-X0-YXe" userLabel="Note View" customClass="View" customModule="Animation" customModuleProvider="target">
<rect key="frame" x="0.0" y="80" width="375" height="130"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Note: exit examples using two-fingers long press" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="rEu-QR-XnT">
Expand All @@ -65,7 +77,7 @@
<constraint firstAttribute="height" constant="94" id="pa2-UV-ax8"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="26"/>
<color key="textColor" red="0.95686274510000002" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.94598448276519775" green="0.95082128047943115" blue="0.95073151588439941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
Expand Down Expand Up @@ -97,7 +109,7 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="xul-vo-SM5" secondAttribute="trailing" constant="-16" id="11Y-ga-9Tk"/>
<constraint firstItem="xul-vo-SM5" firstAttribute="leading" secondItem="xBu-yh-KUm" secondAttribute="leading" id="N5c-wF-YJR"/>
Expand Down Expand Up @@ -129,7 +141,6 @@
</view>
<navigationItem key="navigationItem" id="6hK-VZ-4d7"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="lightContent"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina47"/>
<connections>
<outlet property="noteViewHeightConstraint" destination="lep-Ng-f4d" id="iVH-Hy-tGz"/>
<outlet property="noteViewLabel" destination="rEu-QR-XnT" id="Lgj-YN-1wi"/>
Expand All @@ -146,7 +157,6 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" navigationBarHidden="YES" id="l7B-OX-K3o" customClass="MainNavigationViewController" customModule="Animation" customModuleProvider="target" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="DE8-z8-gw5">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
21 changes: 11 additions & 10 deletions Animation/CubicBezier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -37,24 +37,25 @@ 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;
}

func solveCurveX(x: CGFloat, epsilon: CGFloat) -> CGFloat {

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;
}
Expand All @@ -74,7 +75,7 @@ class CubicBezier: NSObject {
}

while (t0 < t1) {
x2 = sampleCurveX(t2)
x2 = sampleCurveX(t: t2)
if (fabs(x2 - x) < epsilon) {
return t2;
}
Expand Down
12 changes: 6 additions & 6 deletions Animation/Dropdown/DropdownAppearTransitioning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand Down
18 changes: 9 additions & 9 deletions Animation/Dropdown/DropdownDismissTransitioning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand Down
Loading