Skip to content

Commit b992223

Browse files
Merge pull request #8 from mateuszszklarek/swipe-support
Add support UISwipeGestureRecognizer in view
2 parents be2ca23 + 3939670 commit b992223

File tree

15 files changed

+392
-42
lines changed

15 files changed

+392
-42
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.2

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Nimble (7.3.1)
33
- Quick (1.3.2)
44
- SnapKit (4.2.0)
5-
- SpecTools (1.0.3)
5+
- SpecTools (1.1.1)
66

77
DEPENDENCIES:
88
- Nimble
@@ -24,7 +24,7 @@ SPEC CHECKSUMS:
2424
Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae
2525
Quick: 2623cb30d7a7f41ca62f684f679586558f483d46
2626
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
27-
SpecTools: 1215af4f3b7e8e61484a1cdb5e1fb775fa2428bc
27+
SpecTools: 76f96eba2e12f3f9d374ac6b75ce38da97b6ad66
2828

2929
PODFILE CHECKSUM: 75022a650debfd62f749637ced8ed249be1a9563
3030

Example/Pods/Local Podspecs/SpecTools.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SpecTools-iOS/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SpecTools-tvOS/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SpecTools.xcodeproj/project.pbxproj

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
15074DEA1F6443D400E06BD0 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15074DE91F6443D400E06BD0 /* TableViewController.swift */; };
1313
15074DEF1F667F0F00E06BD0 /* TableViewControllerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15074DEE1F667F0F00E06BD0 /* TableViewControllerSpec.swift */; };
1414
15074DF21F6687B400E06BD0 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15074DF11F6687B400E06BD0 /* TableViewCell.swift */; };
15-
15F9BA181F94FF1D00245DF2 /* circle.yml in Resources */ = {isa = PBXBuildFile; fileRef = 15F9BA171F94FF1D00245DF2 /* circle.yml */; };
1615
40E0CC079E7C8FE96ED5C342 /* Pods_TVExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46141C4B85516DCBD9FA4DC0 /* Pods_TVExample.framework */; };
16+
4EEB39D421882998004D9295 /* SwipeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EEB39D321882998004D9295 /* SwipeViewController.swift */; };
1717
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
1818
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
1919
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
2020
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
2121
9742DFBD958C41A0D4A320A7 /* Pods_SpecToolsExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA48DE5F6072FA17B587A4CF /* Pods_SpecToolsExample.framework */; };
2222
C65796F10C08144A51ED4CD8 /* Pods_TVExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D5CA6E801DB8A91D3E70DE6 /* Pods_TVExampleTests.framework */; };
23+
DA62C52F3E9A07FA2E6034DA /* SwipeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6621D12D0DCFD3C5921A21 /* SwipeView.swift */; };
24+
DA674C49DCD23F74F6B91984 /* LabeledView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6F41B96D384A3274587E76 /* LabeledView.swift */; };
25+
DA6C851CF48875F2E30AD9F7 /* SwipeViewControllerSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA68C9608FD96EFF171ED130 /* SwipeViewControllerSpec.swift */; };
2326
F230246CE764371409137DF7 /* Pods_SpecToolsExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4025987761D8603D7A3EF403 /* Pods_SpecToolsExampleTests.framework */; };
2427
F4A8DD811FAB3C3A00237CF6 /* CollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A8DD801FAB3C3A00237CF6 /* CollectionViewController.swift */; };
2528
F4A8DD851FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4A8DD841FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift */; };
@@ -58,11 +61,11 @@
5861
1581B2C91F57711D00DDDA6C /* generate_docs.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = generate_docs.sh; path = ../generate_docs.sh; sourceTree = "<group>"; };
5962
15F9BA131F94FB3500245DF2 /* install.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = install.sh; path = ../Scripts/install.sh; sourceTree = "<group>"; };
6063
15F9BA141F94FB3500245DF2 /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = build.sh; path = ../Scripts/build.sh; sourceTree = "<group>"; };
61-
15F9BA171F94FF1D00245DF2 /* circle.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = circle.yml; path = ../circle.yml; sourceTree = "<group>"; };
6264
1D5CA6E801DB8A91D3E70DE6 /* Pods_TVExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TVExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6365
25476FCE33DB8F6A74FDBAAD /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
6466
4025987761D8603D7A3EF403 /* Pods_SpecToolsExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SpecToolsExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6567
46141C4B85516DCBD9FA4DC0 /* Pods_TVExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TVExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
68+
4EEB39D321882998004D9295 /* SwipeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeViewController.swift; sourceTree = "<group>"; };
6669
573468F956F5B1FC134B10EA /* Pods-TVExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TVExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TVExample/Pods-TVExample.debug.xcconfig"; sourceTree = "<group>"; };
6770
607FACD01AFB9204008FA782 /* SpecToolsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SpecToolsExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
6871
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -77,9 +80,12 @@
7780
A4924F5F25B255B44D41CD79 /* Pods-SpecToolsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecToolsExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-SpecToolsExample/Pods-SpecToolsExample.release.xcconfig"; sourceTree = "<group>"; };
7881
ACE67D9AE3CBE275C0B5F91A /* Pods-SpecTools_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecTools_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SpecTools_Example/Pods-SpecTools_Example.release.xcconfig"; sourceTree = "<group>"; };
7982
B7CF033E9DE2320B8E03AF79 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
80-
CEB96607FEDF79B741ECC275 /* SpecTools.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SpecTools.podspec; path = ../SpecTools.podspec; sourceTree = "<group>"; };
83+
CEB96607FEDF79B741ECC275 /* SpecTools.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SpecTools.podspec; path = ../SpecTools.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
8184
D1BC6C635B933789988F6829 /* Pods-SpecToolsExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecToolsExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SpecToolsExampleTests/Pods-SpecToolsExampleTests.release.xcconfig"; sourceTree = "<group>"; };
8285
DA48DE5F6072FA17B587A4CF /* Pods_SpecToolsExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SpecToolsExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
86+
DA6621D12D0DCFD3C5921A21 /* SwipeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeView.swift; sourceTree = "<group>"; };
87+
DA68C9608FD96EFF171ED130 /* SwipeViewControllerSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwipeViewControllerSpec.swift; sourceTree = "<group>"; };
88+
DA6F41B96D384A3274587E76 /* LabeledView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabeledView.swift; sourceTree = "<group>"; };
8389
DB1653D35AA1B0DA36A7E500 /* Pods-SpecTools_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SpecTools_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SpecTools_Tests/Pods-SpecTools_Tests.release.xcconfig"; sourceTree = "<group>"; };
8490
DFB0C922BA6451420392BB90 /* Pods-TVExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TVExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TVExampleTests/Pods-TVExampleTests.release.xcconfig"; sourceTree = "<group>"; };
8591
E0880E6B85859025B2200B60 /* Pods-TVExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TVExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-TVExample/Pods-TVExample.release.xcconfig"; sourceTree = "<group>"; };
@@ -137,9 +143,10 @@
137143
isa = PBXGroup;
138144
children = (
139145
1504FD4C1F50C6520000D7FA /* BasicSpec.swift */,
140-
1504FD4D1F50C6520000D7FA /* ViewControllerSpec.swift */,
141-
15074DEE1F667F0F00E06BD0 /* TableViewControllerSpec.swift */,
142146
F4A8DD841FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift */,
147+
DA68C9608FD96EFF171ED130 /* SwipeViewControllerSpec.swift */,
148+
15074DEE1F667F0F00E06BD0 /* TableViewControllerSpec.swift */,
149+
1504FD4D1F50C6520000D7FA /* ViewControllerSpec.swift */,
143150
1504FD441F50C5E10000D7FA /* Info.plist */,
144151
);
145152
path = SpecToolsExampleTests;
@@ -149,14 +156,15 @@
149156
isa = PBXGroup;
150157
children = (
151158
15074DF11F6687B400E06BD0 /* TableViewCell.swift */,
159+
DA6621D12D0DCFD3C5921A21 /* SwipeView.swift */,
160+
DA6F41B96D384A3274587E76 /* LabeledView.swift */,
152161
);
153162
name = View;
154163
sourceTree = "<group>";
155164
};
156165
1581B2C81F57710600DDDA6C /* Scripts */ = {
157166
isa = PBXGroup;
158167
children = (
159-
15F9BA171F94FF1D00245DF2 /* circle.yml */,
160168
15F9BA141F94FB3500245DF2 /* build.sh */,
161169
15F9BA131F94FB3500245DF2 /* install.sh */,
162170
1581B2C91F57711D00DDDA6C /* generate_docs.sh */,
@@ -170,6 +178,7 @@
170178
607FACD71AFB9204008FA782 /* ViewController.swift */,
171179
15074DE91F6443D400E06BD0 /* TableViewController.swift */,
172180
F4A8DD801FAB3C3A00237CF6 /* CollectionViewController.swift */,
181+
4EEB39D321882998004D9295 /* SwipeViewController.swift */,
173182
);
174183
name = "View controllers";
175184
sourceTree = "<group>";
@@ -432,7 +441,6 @@
432441
isa = PBXResourcesBuildPhase;
433442
buildActionMask = 2147483647;
434443
files = (
435-
15F9BA181F94FF1D00245DF2 /* circle.yml in Resources */,
436444
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
437445
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
438446
);
@@ -620,6 +628,7 @@
620628
15074DEF1F667F0F00E06BD0 /* TableViewControllerSpec.swift in Sources */,
621629
1504FD4E1F50C6520000D7FA /* BasicSpec.swift in Sources */,
622630
F4A8DD851FAB3FA000237CF6 /* CollectionViewControllerSpecs.swift in Sources */,
631+
DA6C851CF48875F2E30AD9F7 /* SwipeViewControllerSpec.swift in Sources */,
623632
);
624633
runOnlyForDeploymentPostprocessing = 0;
625634
};
@@ -632,6 +641,9 @@
632641
15074DEA1F6443D400E06BD0 /* TableViewController.swift in Sources */,
633642
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
634643
F4A8DD811FAB3C3A00237CF6 /* CollectionViewController.swift in Sources */,
644+
4EEB39D421882998004D9295 /* SwipeViewController.swift in Sources */,
645+
DA62C52F3E9A07FA2E6034DA /* SwipeView.swift in Sources */,
646+
DA674C49DCD23F74F6B91984 /* LabeledView.swift in Sources */,
635647
);
636648
runOnlyForDeploymentPostprocessing = 0;
637649
};

Example/SpecTools/LabeledView.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import SnapKit
2+
import UIKit
3+
4+
class LabeledView: UIView {
5+
6+
let label: UILabel = Subviews.label
7+
8+
init() {
9+
super.init(frame: .zero)
10+
11+
addSubviews()
12+
setUpLayout()
13+
}
14+
15+
// MARK: - Subviews
16+
17+
private func addSubviews() {
18+
addSubview(label)
19+
}
20+
21+
// MARK: - Layout
22+
23+
private func setUpLayout() {
24+
label.snp.makeConstraints {
25+
$0.top.trailing.lessThanOrEqualToSuperview()
26+
$0.bottom.leading.lessThanOrEqualToSuperview()
27+
$0.center.equalToSuperview()
28+
}
29+
}
30+
31+
// MARK: - Required initializer
32+
33+
required init?(coder _: NSCoder) { return nil }
34+
35+
}
36+
37+
private extension LabeledView {
38+
39+
enum Subviews {
40+
static var label: UILabel {
41+
let label = UILabel(frame: .zero)
42+
label.textColor = .white
43+
label.font = UIFont.systemFont(ofSize: 15.0, weight: .bold)
44+
label.textAlignment = .center
45+
46+
return label
47+
}
48+
}
49+
50+
}

Example/SpecTools/SwipeView.swift

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import UIKit
2+
import SnapKit
3+
4+
class SwipeView: UIView {
5+
6+
let upView: UIView = Subviews.view(color: .green, text: "UP")
7+
let leftView: UIView = Subviews.view(color: .red, text: "LEFT")
8+
let rightView: UIView = Subviews.view(color: .blue, text: "RIGHT")
9+
let downView: UIView = Subviews.view(color: .gray, text: "DOWN")
10+
11+
init() {
12+
super.init(frame: .zero)
13+
14+
setUpSelf()
15+
addSubviews()
16+
setupLayout()
17+
}
18+
19+
private func setUpSelf() {
20+
backgroundColor = .white
21+
}
22+
23+
// MARK: Subviews
24+
25+
private let stackView: UIStackView = Subviews.stackView
26+
27+
private func addSubviews() {
28+
[upView, leftView, rightView, downView].forEach {
29+
stackView.addArrangedSubview($0)
30+
}
31+
32+
addSubview(stackView)
33+
}
34+
35+
// MARK: Layout
36+
37+
private func setupLayout() {
38+
stackView.snp.makeConstraints {
39+
$0.edges.equalToSuperview()
40+
}
41+
42+
[upView, leftView, rightView, downView].forEach { view in
43+
view.snp.makeConstraints {
44+
$0.width.equalToSuperview()
45+
}
46+
}
47+
}
48+
49+
// MARK: - Required initializer
50+
51+
required init?(coder _: NSCoder) { return nil }
52+
53+
}
54+
55+
private extension SwipeView {
56+
57+
enum Subviews {
58+
static func view(color: UIColor, text: String) -> LabeledView {
59+
let view = LabeledView()
60+
view.backgroundColor = color
61+
view.label.text = text
62+
63+
return view
64+
}
65+
66+
static var stackView: UIStackView {
67+
let stackView = UIStackView(frame: .zero)
68+
stackView.axis = .vertical
69+
stackView.alignment = .center
70+
stackView.distribution = .fillEqually
71+
stackView.spacing = 5
72+
73+
return stackView
74+
}
75+
}
76+
77+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import UIKit
2+
3+
class SwipeViewController: UIViewController {
4+
5+
var didSwipeUp: (() -> Void)?
6+
var didSwipeLeft: (() -> Void)?
7+
var didSwipeRight: (() -> Void)?
8+
var didSwipeDown: (() -> Void)?
9+
10+
var swipeView: SwipeView { return view as! SwipeView }
11+
12+
// MARK: - Lifecycle
13+
14+
override func loadView() {
15+
view = SwipeView()
16+
}
17+
18+
override func viewDidLoad() {
19+
super.viewDidLoad()
20+
21+
setUpSwipeGestures()
22+
}
23+
24+
// MARK: - Private
25+
26+
private func setUpSwipeGestures() {
27+
setUpSwipeGesture(direction: .up, action: #selector(swipedUp), in: swipeView.upView)
28+
setUpSwipeGesture(direction: .left, action: #selector(swipedLeft), in: swipeView.leftView)
29+
setUpSwipeGesture(direction: .right, action: #selector(swipedRight), in: swipeView.rightView)
30+
setUpSwipeGesture(direction: .down, action: #selector(swipedDown), in: swipeView.downView)
31+
}
32+
33+
// MARK: Actions
34+
35+
private func setUpSwipeGesture(direction: UISwipeGestureRecognizer.Direction, action: Selector?, in view: UIView) {
36+
let swipeGesture = UISwipeGestureRecognizer(target: self, action: action)
37+
swipeGesture.direction = direction
38+
view.addGestureRecognizer(swipeGesture)
39+
}
40+
41+
@objc
42+
private func swipedUp() {
43+
print("SWIPED UP")
44+
didSwipeUp?()
45+
}
46+
47+
@objc
48+
private func swipedLeft() {
49+
print("SWIPED LEFT")
50+
didSwipeLeft?()
51+
}
52+
53+
@objc
54+
private func swipedRight() {
55+
print("SWIPED RIGHT")
56+
didSwipeRight?()
57+
}
58+
59+
@objc
60+
private func swipedDown() {
61+
print("SWIPED DOWN")
62+
didSwipeDown?()
63+
}
64+
65+
}

0 commit comments

Comments
 (0)