Skip to content

Commit 67b8bad

Browse files
committed
Add SpringImageView, SpringLabel, SpringTextField, SpringTextView
1 parent 031a1d4 commit 67b8bad

File tree

4 files changed

+268
-0
lines changed

4 files changed

+268
-0
lines changed

Spring/SpringImageView.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// SpringImageView.swift
3+
// SpringApp
4+
//
5+
// Created by James Tang on 15/1/15.
6+
// Copyright (c) 2015 Meng To. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringImageView: UIImageView, Springable {
12+
13+
@IBInspectable var animation: String = ""
14+
15+
@IBInspectable var force: CGFloat = 1
16+
@IBInspectable var delay: CGFloat = 0
17+
@IBInspectable var duration: CGFloat = 0.7
18+
@IBInspectable var damping: CGFloat = 0.7
19+
@IBInspectable var velocity: CGFloat = 0.7
20+
@IBInspectable var x: CGFloat = 0
21+
@IBInspectable var y: CGFloat = 0
22+
@IBInspectable var scaleX: CGFloat = 1
23+
@IBInspectable var scaleY: CGFloat = 1
24+
@IBInspectable var rotate: CGFloat = 0
25+
@IBInspectable var opacity: CGFloat = 1
26+
@IBInspectable var animateFrom: Bool = false
27+
@IBInspectable var curve: String = ""
28+
29+
private var spring : Spring!
30+
31+
required init(coder aDecoder: NSCoder) {
32+
super.init(coder: aDecoder)
33+
self.commonInit()
34+
}
35+
36+
override init(frame: CGRect) {
37+
super.init(frame: frame)
38+
self.commonInit()
39+
}
40+
41+
func commonInit() {
42+
self.spring = Spring(self)
43+
}
44+
45+
override func setValue(value: AnyObject?, forKey key: String) {
46+
if !self.spring.setSpringValue(value, forKey: key) {
47+
super.setValue(value, forKey: key)
48+
}
49+
}
50+
51+
override func awakeFromNib() {
52+
super.awakeFromNib()
53+
self.spring.awakeFromNib()
54+
}
55+
56+
func animate() {
57+
self.spring.animate()
58+
}
59+
60+
func animateNext(completion: () -> ()) {
61+
self.spring.animateNext(completion)
62+
}
63+
64+
func animateToNext(completion: () -> ()) {
65+
self.spring.animateToNext(completion)
66+
}
67+
}

Spring/SpringLabel.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// SpringLabel.swift
3+
// SpringApp
4+
//
5+
// Created by James Tang on 15/1/15.
6+
// Copyright (c) 2015 Meng To. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringLabel: UILabel, Springable {
12+
13+
@IBInspectable var animation: String = ""
14+
15+
@IBInspectable var force: CGFloat = 1
16+
@IBInspectable var delay: CGFloat = 0
17+
@IBInspectable var duration: CGFloat = 0.7
18+
@IBInspectable var damping: CGFloat = 0.7
19+
@IBInspectable var velocity: CGFloat = 0.7
20+
@IBInspectable var x: CGFloat = 0
21+
@IBInspectable var y: CGFloat = 0
22+
@IBInspectable var scaleX: CGFloat = 1
23+
@IBInspectable var scaleY: CGFloat = 1
24+
@IBInspectable var rotate: CGFloat = 0
25+
@IBInspectable var opacity: CGFloat = 1
26+
@IBInspectable var animateFrom: Bool = false
27+
@IBInspectable var curve: String = ""
28+
29+
private var spring : Spring!
30+
31+
required init(coder aDecoder: NSCoder) {
32+
super.init(coder: aDecoder)
33+
self.commonInit()
34+
}
35+
36+
override init(frame: CGRect) {
37+
super.init(frame: frame)
38+
self.commonInit()
39+
}
40+
41+
func commonInit() {
42+
self.spring = Spring(self)
43+
}
44+
45+
override func setValue(value: AnyObject?, forKey key: String) {
46+
if !self.spring.setSpringValue(value, forKey: key) {
47+
super.setValue(value, forKey: key)
48+
}
49+
}
50+
51+
override func awakeFromNib() {
52+
super.awakeFromNib()
53+
self.spring.awakeFromNib()
54+
}
55+
56+
func animate() {
57+
self.spring.animate()
58+
}
59+
60+
func animateNext(completion: () -> ()) {
61+
self.spring.animateNext(completion)
62+
}
63+
64+
func animateToNext(completion: () -> ()) {
65+
self.spring.animateToNext(completion)
66+
}
67+
}

Spring/SpringTextField.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// SpringTextField.swift
3+
// SpringApp
4+
//
5+
// Created by James Tang on 15/1/15.
6+
// Copyright (c) 2015 Meng To. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringTextField: UITextField, Springable {
12+
13+
@IBInspectable var animation: String = ""
14+
15+
@IBInspectable var force: CGFloat = 1
16+
@IBInspectable var delay: CGFloat = 0
17+
@IBInspectable var duration: CGFloat = 0.7
18+
@IBInspectable var damping: CGFloat = 0.7
19+
@IBInspectable var velocity: CGFloat = 0.7
20+
@IBInspectable var x: CGFloat = 0
21+
@IBInspectable var y: CGFloat = 0
22+
@IBInspectable var scaleX: CGFloat = 1
23+
@IBInspectable var scaleY: CGFloat = 1
24+
@IBInspectable var rotate: CGFloat = 0
25+
@IBInspectable var opacity: CGFloat = 1
26+
@IBInspectable var animateFrom: Bool = false
27+
@IBInspectable var curve: String = ""
28+
29+
private var spring : Spring!
30+
31+
required init(coder aDecoder: NSCoder) {
32+
super.init(coder: aDecoder)
33+
self.commonInit()
34+
}
35+
36+
override init(frame: CGRect) {
37+
super.init(frame: frame)
38+
self.commonInit()
39+
}
40+
41+
func commonInit() {
42+
self.spring = Spring(self)
43+
}
44+
45+
override func setValue(value: AnyObject?, forKey key: String) {
46+
if !self.spring.setSpringValue(value, forKey: key) {
47+
super.setValue(value, forKey: key)
48+
}
49+
}
50+
51+
override func awakeFromNib() {
52+
super.awakeFromNib()
53+
self.spring.awakeFromNib()
54+
}
55+
56+
func animate() {
57+
self.spring.animate()
58+
}
59+
60+
func animateNext(completion: () -> ()) {
61+
self.spring.animateNext(completion)
62+
}
63+
64+
func animateToNext(completion: () -> ()) {
65+
self.spring.animateToNext(completion)
66+
}
67+
}

Spring/SpringTextView.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// SpringTextView.swift
3+
// SpringApp
4+
//
5+
// Created by James Tang on 15/1/15.
6+
// Copyright (c) 2015 Meng To. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringTextView: UITextView, Springable {
12+
13+
@IBInspectable var animation: String = ""
14+
15+
@IBInspectable var force: CGFloat = 1
16+
@IBInspectable var delay: CGFloat = 0
17+
@IBInspectable var duration: CGFloat = 0.7
18+
@IBInspectable var damping: CGFloat = 0.7
19+
@IBInspectable var velocity: CGFloat = 0.7
20+
@IBInspectable var x: CGFloat = 0
21+
@IBInspectable var y: CGFloat = 0
22+
@IBInspectable var scaleX: CGFloat = 1
23+
@IBInspectable var scaleY: CGFloat = 1
24+
@IBInspectable var rotate: CGFloat = 0
25+
@IBInspectable var opacity: CGFloat = 1
26+
@IBInspectable var animateFrom: Bool = false
27+
@IBInspectable var curve: String = ""
28+
29+
private var spring : Spring!
30+
31+
required init(coder aDecoder: NSCoder) {
32+
super.init(coder: aDecoder)
33+
self.commonInit()
34+
}
35+
36+
override init(frame: CGRect) {
37+
super.init(frame: frame)
38+
self.commonInit()
39+
}
40+
41+
func commonInit() {
42+
self.spring = Spring(self)
43+
}
44+
45+
override func setValue(value: AnyObject?, forKey key: String) {
46+
if !self.spring.setSpringValue(value, forKey: key) {
47+
super.setValue(value, forKey: key)
48+
}
49+
}
50+
51+
override func awakeFromNib() {
52+
super.awakeFromNib()
53+
self.spring.awakeFromNib()
54+
}
55+
56+
func animate() {
57+
self.spring.animate()
58+
}
59+
60+
func animateNext(completion: () -> ()) {
61+
self.spring.animateNext(completion)
62+
}
63+
64+
func animateToNext(completion: () -> ()) {
65+
self.spring.animateToNext(completion)
66+
}
67+
}

0 commit comments

Comments
 (0)