Skip to content

Commit a7f8ece

Browse files
committed
Version 0.1.2
1 parent 0eefa22 commit a7f8ece

File tree

9 files changed

+36
-21
lines changed

9 files changed

+36
-21
lines changed

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- SwipeViewController (0.1.1)
2+
- SwipeViewController (0.1.2)
33

44
DEPENDENCIES:
55
- SwipeViewController (from `../`)
@@ -9,6 +9,6 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
SwipeViewController: 0a2fb9b4266a8f1be1662d022114518581322bb7
12+
SwipeViewController: b80bc7199c81955d20c8d78e687c2aae11ec3595
1313

1414
COCOAPODS: 0.39.0

Example/Pods/Local Podspecs/SwipeViewController.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/Pods.xcodeproj/xcshareddata/xcschemes/SwipeViewController.xcscheme

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/SwipeViewController/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/SwipeViewController/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ViewController: SwipeViewController {
2626

2727

2828
setViewControllerArray([VC1, VC2, VC3])
29+
setFirstViewController(1)
2930
setSelectionBar(80, height: 3, color: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
3031
setButtonsWithSelectedColor(UIFont.systemFontOfSize(18), color: UIColor.blackColor(), selectedColor: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
3132

Pod/Classes/SwipeViewController.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
1717
//SelectionBar
1818
var selectionBarHeight = CGFloat(0)
1919
var selectionBarWidth = CGFloat(0)
20-
var selectionBarColor = UIColor()
20+
var selectionBarColor = UIColor.blackColor()
2121

2222
//SwipeButtons
2323
var offset = CGFloat(40)
2424
var bottomOfset = CGFloat(0)
25-
var buttonColor = UIColor.whiteColor()
26-
var selectedButtonColor = UIColor.orangeColor()
25+
var buttonColor = UIColor.blackColor()
26+
var selectedButtonColor = UIColor.greenColor()
2727
var buttonFont = UIFont.systemFontOfSize(18)
28-
var currentPageIndex = 2 //Besides keeping current page index it also determines what will be the first view
28+
var currentPageIndex = 1 //Besides keeping current page index it also determines what will be the first view
2929

3030
//NavigationBar
3131
var navigationBarColor = UIColor.whiteColor()
@@ -39,13 +39,14 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
3939
var viewWidth = CGFloat()
4040
var x = 0 as CGFloat //Distance between elements
4141
var barButtonItemWidth = CGFloat(8) //Extra offset when there is barButtonItem (and some default, you can check the value by pageController.navigationController?.navigationBar.topItem?.titleView?.layoutMargins.left
42-
var navigationBarHeight = 0 as CGFloat
42+
var navigationBarHeight = CGFloat(0)
4343
var selectionBar = UIView()
4444
var pageController = UIPageViewController()
4545
var totalButtonWidth = CGFloat(0)
4646
var finalPageIndex = -1
4747
var indexNotIncremented = true
4848
var pageScrollView = UIScrollView()
49+
var animationFinished = true
4950

5051
var selectionBarDelegate: SelectionBar?
5152

@@ -97,6 +98,10 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
9798
pageArray.append(viewController)
9899
}
99100

101+
public func setFirstViewController(viewControllerIndex: Int) {
102+
currentPageIndex = viewControllerIndex + 1
103+
}
104+
100105
public func setSelectionBar(width: CGFloat, height: CGFloat, color: UIColor) {
101106
selectionBarWidth = width
102107
selectionBarHeight = height
@@ -145,12 +150,12 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
145150

146151
public func scrollViewDidScroll(scrollView: UIScrollView) {
147152

148-
149153
let xFromCenter = view.frame.size.width - scrollView.contentOffset.x
150154
var width = 0 as CGFloat
151-
155+
//print(xFromCenter)
152156
let border = viewWidth - 1
153157

158+
154159
guard currentPageIndex > 0 && currentPageIndex <= buttons.count else {return}
155160

156161
//Ensuring currentPageIndex is not changed twice
@@ -161,22 +166,24 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
161166
//Resetting finalPageIndex for switching tabs
162167
if xFromCenter == 0 {
163168
finalPageIndex = -1
169+
animationFinished = true
164170
}
165171

166172
//Going right
167-
if xFromCenter <= -viewWidth && indexNotIncremented {
173+
if xFromCenter <= -viewWidth && indexNotIncremented && currentPageIndex < buttons.count {
168174
view.backgroundColor = pageArray[currentPageIndex].view.backgroundColor
169175
currentPageIndex += 1
170176
indexNotIncremented = false
171177
}
172178

173179
//Going left
174-
else if xFromCenter >= viewWidth && indexNotIncremented {
180+
else if xFromCenter >= viewWidth && indexNotIncremented && currentPageIndex >= 2 {
175181
view.backgroundColor = pageArray[currentPageIndex - 2].view.backgroundColor
176182
currentPageIndex -= 1
177183
indexNotIncremented = false
178184
}
179185

186+
180187
if buttonColor != selectedButtonColor {
181188
changeButtonColor(xFromCenter)
182189
}
@@ -228,13 +235,14 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
228235

229236
//loop - if user goes from tab 1 to tab 3 we want to have tab 2 in animation
230237
for viewControllerIndex in currentViewControllerIndex...index {
231-
232238
let destinationViewController = pageArray[viewControllerIndex]
233-
pageController.setViewControllers([destinationViewController], direction: .Forward, animated: true, completion: nil)
239+
pageController.setViewControllers([destinationViewController], direction: .Forward, animated: true, completion:nil)
240+
234241
}
235242
}
236243
//Index is on the left
237244
else {
245+
238246
for viewControllerIndex in (index...currentViewControllerIndex).reverse() {
239247
let destinationViewController = pageArray[viewControllerIndex]
240248
pageController.setViewControllers([destinationViewController], direction: .Reverse, animated: true, completion: nil)
@@ -249,8 +257,9 @@ public class SwipeViewController: UINavigationController, UIPageViewControllerDe
249257
let index = sender.tag - 1
250258

251259
//Can't animate twice to the same controller (otherwise weird stuff happens)
252-
guard index != finalPageIndex else {return}
260+
guard index != finalPageIndex && index != currentPageIndex - 1 && animationFinished else {return}
253261

262+
animationFinished = false
254263
finalPageIndex = index
255264
scrollToNextViewController(index)
256265
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ To set the titles of the buttons, you just need to change the title of each page
8080
```swift
8181
page_one.title = "Recent"
8282
```
83+
To specify which view controller should be selected first:
84+
```swift
85+
setFirstViewController(1)
86+
```
87+
It should also be said that the first view controller index starts at zero, just like arrays.
8388

8489
### NavigationBar
8590

SwipeViewController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "SwipeViewController"
11-
s.version = "0.1.1"
11+
s.version = "0.1.2"
1212
s.summary = "Subclass of UIPageViewController and UINavigation for easy navigation"
1313

1414
# This description is used to generate tags and improve search results.

0 commit comments

Comments
 (0)