Skip to content

Commit 3a2a075

Browse files
committed
Add Spring Animation
1 parent 34a976a commit 3a2a075

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

iOSAnimationSample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
AE17FD3E1AF820ED0086BC39 /* RepeatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17FD3D1AF820ED0086BC39 /* RepeatViewController.swift */; };
1111
AE17FD401AF824990086BC39 /* EasingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17FD3F1AF824990086BC39 /* EasingViewController.swift */; };
12+
AE17FD421AF8A84B0086BC39 /* SpringViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17FD411AF8A84B0086BC39 /* SpringViewController.swift */; };
1213
AE337B3C1AF260C0005F4AE1 /* ScaleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE337B3B1AF260C0005F4AE1 /* ScaleViewController.swift */; };
1314
AE337B3E1AF26525005F4AE1 /* ColorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE337B3D1AF26525005F4AE1 /* ColorViewController.swift */; };
1415
AE337B401AF2E1F0005F4AE1 /* RotationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE337B3F1AF2E1F0005F4AE1 /* RotationViewController.swift */; };
@@ -35,6 +36,7 @@
3536
/* Begin PBXFileReference section */
3637
AE17FD3D1AF820ED0086BC39 /* RepeatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepeatViewController.swift; sourceTree = "<group>"; };
3738
AE17FD3F1AF824990086BC39 /* EasingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EasingViewController.swift; sourceTree = "<group>"; };
39+
AE17FD411AF8A84B0086BC39 /* SpringViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpringViewController.swift; sourceTree = "<group>"; };
3840
AE337B3B1AF260C0005F4AE1 /* ScaleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScaleViewController.swift; sourceTree = "<group>"; };
3941
AE337B3D1AF26525005F4AE1 /* ColorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorViewController.swift; sourceTree = "<group>"; };
4042
AE337B3F1AF2E1F0005F4AE1 /* RotationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RotationViewController.swift; sourceTree = "<group>"; };
@@ -100,6 +102,7 @@
100102
AE337B3F1AF2E1F0005F4AE1 /* RotationViewController.swift */,
101103
AE17FD3D1AF820ED0086BC39 /* RepeatViewController.swift */,
102104
AE17FD3F1AF824990086BC39 /* EasingViewController.swift */,
105+
AE17FD411AF8A84B0086BC39 /* SpringViewController.swift */,
103106
AECE40131AEF7274005A5415 /* Main.storyboard */,
104107
AECE40161AEF7274005A5415 /* Images.xcassets */,
105108
AECE40181AEF7274005A5415 /* LaunchScreen.xib */,
@@ -236,6 +239,7 @@
236239
AECE40301AF03D91005A5415 /* PositionViewController.swift in Sources */,
237240
AE337B3C1AF260C0005F4AE1 /* ScaleViewController.swift in Sources */,
238241
AE17FD401AF824990086BC39 /* EasingViewController.swift in Sources */,
242+
AE17FD421AF8A84B0086BC39 /* SpringViewController.swift in Sources */,
239243
AECE40121AEF7274005A5415 /* ViewController.swift in Sources */,
240244
AE8A3A591AF2598200815F4B /* OpacityViewController.swift in Sources */,
241245
AE337B401AF2E1F0005F4AE1 /* RotationViewController.swift in Sources */,

iOSAnimationSample/Base.lproj/Main.storyboard

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@
148148
<segue destination="kNR-0P-iRv" kind="push" id="dBp-KC-URn"/>
149149
</connections>
150150
</tableViewCell>
151+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="QNK-ME-tpn" style="IBUITableViewCellStyleDefault" id="MHb-1k-OAg">
152+
<rect key="frame" x="0.0" y="372" width="320" height="44"/>
153+
<autoresizingMask key="autoresizingMask"/>
154+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="MHb-1k-OAg" id="Lac-ab-EVb">
155+
<rect key="frame" x="0.0" y="0.0" width="287" height="43"/>
156+
<autoresizingMask key="autoresizingMask"/>
157+
<subviews>
158+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Spring" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="QNK-ME-tpn">
159+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
160+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
161+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
162+
<nil key="highlightedColor"/>
163+
</label>
164+
</subviews>
165+
</tableViewCellContentView>
166+
<connections>
167+
<segue destination="5SL-sW-2kh" kind="push" id="YAC-Ah-LxN"/>
168+
</connections>
169+
</tableViewCell>
151170
</cells>
152171
</tableViewSection>
153172
</sections>
@@ -415,6 +434,43 @@
415434
</objects>
416435
<point key="canvasLocation" x="1052" y="4200"/>
417436
</scene>
437+
<!--Spring View Controller-->
438+
<scene sceneID="NTb-oo-DO3">
439+
<objects>
440+
<viewController id="5SL-sW-2kh" customClass="SpringViewController" customModule="iOSAnimationSample" customModuleProvider="target" sceneMemberID="viewController">
441+
<view key="view" contentMode="scaleToFill" id="TQj-9M-vQF">
442+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
443+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
444+
<subviews>
445+
<view contentMode="scaleToFill" id="iWf-yi-ptL">
446+
<rect key="frame" x="16" y="85" width="60" height="60"/>
447+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
448+
<color key="backgroundColor" red="0.22802925860000001" green="0.66314832059999995" blue="0.70600328950000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
449+
</view>
450+
<view contentMode="scaleToFill" id="yjO-xK-5sm">
451+
<rect key="frame" x="16" y="164" width="60" height="60"/>
452+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
453+
<color key="backgroundColor" red="0.96142769610000001" green="0.19560617420000001" blue="0.27446546059999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
454+
</view>
455+
<view contentMode="scaleToFill" id="2qF-m6-ebs">
456+
<rect key="frame" x="16" y="240" width="60" height="60"/>
457+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
458+
<color key="backgroundColor" red="0.40933579640000001" green="0.80104922519999999" blue="0.036929481930000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
459+
</view>
460+
</subviews>
461+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
462+
</view>
463+
<navigationItem key="navigationItem" id="3sQ-uc-KxC"/>
464+
<connections>
465+
<outlet property="blueSquare" destination="iWf-yi-ptL" id="NTg-70-jhs"/>
466+
<outlet property="greenSquare" destination="2qF-m6-ebs" id="i9d-R6-3GK"/>
467+
<outlet property="redSquare" destination="yjO-xK-5sm" id="uMo-dP-qiO"/>
468+
</connections>
469+
</viewController>
470+
<placeholder placeholderIdentifier="IBFirstResponder" id="DE8-cV-mPb" userLabel="First Responder" sceneMemberID="firstResponder"/>
471+
</objects>
472+
<point key="canvasLocation" x="1052" y="4847"/>
473+
</scene>
418474
</scenes>
419475
<resources>
420476
<image name="wheel" width="894" height="894"/>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// SpringViewController.swift
3+
// iOSAnimationSample
4+
//
5+
// Created by Jake Lin on 5/5/15.
6+
// Copyright (c) 2015 JakeLin. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringViewController: UIViewController {
12+
13+
@IBOutlet weak var blueSquare: UIView!
14+
@IBOutlet weak var redSquare: UIView!
15+
@IBOutlet weak var greenSquare: UIView!
16+
override func viewDidLoad() {
17+
super.viewDidLoad()
18+
19+
// Do any additional setup after loading the view.
20+
}
21+
22+
override func didReceiveMemoryWarning() {
23+
super.didReceiveMemoryWarning()
24+
// Dispose of any resources that can be recreated.
25+
}
26+
27+
override func viewDidAppear(animated: Bool) {
28+
UIView.animateWithDuration(1, animations: {
29+
self.blueSquare.center.x = self.view.bounds.width - self.blueSquare.center.x
30+
})
31+
32+
UIView.animateWithDuration(5, delay: 0, usingSpringWithDamping: 0.1, initialSpringVelocity: 0, options: nil, animations: {
33+
self.redSquare.center.x = self.view.bounds.width - self.redSquare.center.x
34+
}, completion: nil)
35+
36+
UIView.animateWithDuration(5, delay: 0, usingSpringWithDamping: 0.1, initialSpringVelocity: 1, options: nil, animations: {
37+
self.greenSquare.center.x = self.view.bounds.width - self.greenSquare.center.x
38+
}, completion: nil)
39+
}
40+
41+
/*
42+
// MARK: - Navigation
43+
44+
// In a storyboard-based application, you will often want to do a little preparation before navigation
45+
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
46+
// Get the new view controller using segue.destinationViewController.
47+
// Pass the selected object to the new view controller.
48+
}
49+
*/
50+
51+
}

0 commit comments

Comments
 (0)