You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-24
Original file line number
Diff line number
Diff line change
@@ -26,67 +26,140 @@ Then import it using:
26
26
27
27
Usage
28
28
---
29
-
Check out the [demo app](https://github.com/zhxnlai/ZLSwipeableViewSwift/archive/master.zip) for an example. It contains the following demos: Default, Custom Animation, Custom Swipe, Custom Directionand Undo.
29
+
Check out the [demo app](https://github.com/zhxnlai/ZLSwipeableViewSwift/archive/master.zip) for an example. It contains the following demos: Default, Custom Animation, Custom Swipe, Allowed Direction, History, Previous View, Should Swipe and Always Swipe.
30
30
31
+
### Instantiation
31
32
`ZLSwipeableView` can be added to storyboard or instantiated programmatically:
The `nextView` property, a closure that returns an `UIView`, is used to provide subviews to `ZLSwipeableView`. After defining it, you can call `loadViews` and `ZLSwipeableView` will invoke `nextView``numPrefetchedViews` times and animate the prefetched views.
38
+
### Adding Views
39
+
`ZLSwipeableView` supports both adding views to the front and to the back.
38
40
~~~swift
41
+
publicvar numberOfActiveView =UInt(4)
42
+
publicvar nextView: (() -> UIView?)?
43
+
publicvar previousView: (() -> UIView?)?
44
+
~~~
45
+
#### Adding views to the back
46
+
`nextView`, a closure that returns an `UIView`, works with `loadViews` and `numberOfActiveView`. It acts as the data source. After defining it, `ZLSwipeableView` will call `loadViews` which will invoke `nextView``numberOfActiveView` times and insert them in the back. `loadViews` will also be called each time a view is swiped.
47
+
48
+
~~~swift
49
+
publicfuncloadViews()
50
+
// Usage:
51
+
swipeableView.numPrefetchedViews=3
39
52
swipeableView.nextView= {
40
53
returnUIView()
41
54
}
42
-
swipeableView.numPrefetchedViews=3
43
-
swipeableView.loadViews()
55
+
swipeableView.loadViews() // optional, automatically call after nextView is set
56
+
~~~
57
+
58
+
#### Adding views to the front
59
+
`previousView` works with `rewind`, which inserts a view in the front and positions it at the center with animation.
60
+
Note that `rewind` calls `previousView` only when `history` is empty, otherwise it returns the most recently swiped view. Please try out the [Previous View](#rewind) example for more information.
61
+
~~~swift
62
+
publicfuncrewind()
63
+
// Usage:
64
+
swipeableView.previousView= {
65
+
returnUIView()
66
+
}
67
+
swipeableView.rewind()
44
68
~~~
45
69
46
-
The demo app includes examples of both creating views programmatically and loading views from Xib files that [use Auto Layout](https://github.com/zhxnlai/ZLSwipeableView/issues/9).
70
+
#### Interface Builder
71
+
If you need to work with Interface Builder, the demo app includes examples of both creating views programmatically and loading views from Xib files that [use Auto Layout](https://github.com/zhxnlai/ZLSwipeableView/issues/9).
72
+
73
+
### Removing Views
74
+
75
+
#### Swiping programmatically
76
+
The user can swipe views in the allowed directions. This can also happen programmatically.
77
+
78
+
You can swipe the top view programmatically in one of the predefined directions or with point and direction in the view's coordinate.
`ZLSwipeableView` keeps a history of swiped views. They can be retrieved by calling `rewind`.
94
+
~~~swift
95
+
publicvar history = [UIView]()
96
+
publicvar numberOfHistoryItem =UInt(10)
97
+
98
+
publicfuncrewind()
99
+
~~~
100
+
101
+
#### Removing all views
102
+
To discard all views and reload programmatically (discarded views cannot by rewinded):
49
103
~~~swift
50
104
swipeableView.discardViews()
51
105
swipeableView.loadViews()
52
106
~~~
53
107
54
-
You can limit the direction swiping happens using the `direction` property and register callbacks like this. Take a look at the [Custom Direction](#custom-direction) example for details.
108
+
### Delegate
109
+
Here is a list of callbacks you can listen to:
55
110
~~~swift
56
-
swipeableView.direction= .Left| .Up
57
-
swipeableView.direction= .All
58
-
59
111
swipeableView.didStart= {view, location in
60
-
println("Did start swiping view at location: \(location)")
112
+
print("Did start swiping view at location: \(location)")
61
113
}
62
114
swipeableView.swiping= {view, location, translation in
63
-
println("Swiping at view location: \(location) translation: \(translation)")
115
+
print("Swiping at view location: \(location) translation: \(translation)")
64
116
}
65
117
swipeableView.didEnd= {view, location in
66
-
println("Did end swiping view at location: \(location)")
118
+
print("Did end swiping view at location: \(location)")
67
119
}
68
120
swipeableView.didSwipe= {view, direction, vector in
69
-
println("Did swipe view in direction: \(direction), vector: \(vector)")
121
+
print("Did swipe view in direction: \(direction), vector: \(vector)")
70
122
}
71
123
swipeableView.didCancel= {view in
72
-
println("Did cancel swiping view")
124
+
print("Did cancel swiping view")
73
125
}
74
126
~~~
75
127
76
-
You can swipe the top view programmatically in one of the predefined directions or with any point and direction in the view's coordinate.
You can also change how the direction gets interpreted by overriding the `interpretDirection` property. Take a look at the [Custom Swipe](#custom-swipe) example for details.
86
139
140
+
#### interpretDirection
141
+
You can change how the direction gets interpreted by overriding the `interpretDirection` property. Take a look at the [Custom Swipe](#custom-swipe) example for details.
142
+
143
+
#### animateView
87
144
You can create custom animation by overriding the `animateView` property. Take a look at the [Custom Animation](#custom-animation) example for details.
88
145
89
-
You can undo/rewind by storing the swiped views and insert them back to the top by calling `insertTopView`. Take a look at the [Undo](#undo) example for details.
146
+
#### Should Swipe
147
+
`shouldSwipeView`, `minTranslationInPercent` and `minVelocityInPointPerSecond` determines whether a view should be swiped or not. Please see Should Swipe example for details.
148
+
149
+
#### allowedDirection
150
+
The `allowedDirection` property limits the directions in which the user is allowed to swipe. Please see the [Custom Direction](#custom-direction) example for details.
0 commit comments