Skip to content

Commit f2bbbb7

Browse files
committed
update README
1 parent bcec8b2 commit f2bbbb7

File tree

1 file changed

+97
-24
lines changed

1 file changed

+97
-24
lines changed

README.md

+97-24
Original file line numberDiff line numberDiff line change
@@ -26,67 +26,140 @@ Then import it using:
2626

2727
Usage
2828
---
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 Direction and 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.
3030

31+
### Instantiation
3132
`ZLSwipeableView` can be added to storyboard or instantiated programmatically:
3233
~~~swift
3334
var swipeableView = ZLSwipeableView(frame: CGRect(x: 0, y: 0, width: 300, height: 500)))
3435
view.addSubview(swipeableView)
3536
~~~
3637

37-
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.
3840
~~~swift
41+
public var numberOfActiveView = UInt(4)
42+
public var nextView: (() -> UIView?)?
43+
public var 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+
public func loadViews()
50+
// Usage:
51+
swipeableView.numPrefetchedViews = 3
3952
swipeableView.nextView = {
4053
return UIView()
4154
}
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+
public func rewind()
63+
// Usage:
64+
swipeableView.previousView = {
65+
return UIView()
66+
}
67+
swipeableView.rewind()
4468
~~~
4569

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.
79+
~~~swift
80+
public func swipeTopView(inDirection direction: Direction)
81+
// Usage:
82+
swipeableView.swipeTopView(inDirection: .Left)
83+
swipeableView.swipeTopView(inDirection: .Up)
84+
swipeableView.swipeTopView(inDirection: .Right)
85+
swipeableView.swipeTopView(inDirection: .Down)
86+
87+
public func swipeTopView(fromPoint location: CGPoint, inDirection directionVector: CGVector)
88+
// Usage:
89+
swipeableView.swipeTopView(fromPoint: CGPoint(x: 100, y: 30), inDirection: CGVector(dx: 100, dy: -800))
90+
~~~
4791

48-
To discard all views and reload programmatically:
92+
#### Rewinding
93+
`ZLSwipeableView` keeps a history of swiped views. They can be retrieved by calling `rewind`.
94+
~~~swift
95+
public var history = [UIView]()
96+
public var numberOfHistoryItem = UInt(10)
97+
98+
public func rewind()
99+
~~~
100+
101+
#### Removing all views
102+
To discard all views and reload programmatically (discarded views cannot by rewinded):
49103
~~~swift
50104
swipeableView.discardViews()
51105
swipeableView.loadViews()
52106
~~~
53107

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:
55110
~~~swift
56-
swipeableView.direction = .Left | .Up
57-
swipeableView.direction = .All
58-
59111
swipeableView.didStart = {view, location in
60-
println("Did start swiping view at location: \(location)")
112+
print("Did start swiping view at location: \(location)")
61113
}
62114
swipeableView.swiping = {view, location, translation in
63-
println("Swiping at view location: \(location) translation: \(translation)")
115+
print("Swiping at view location: \(location) translation: \(translation)")
64116
}
65117
swipeableView.didEnd = {view, location in
66-
println("Did end swiping view at location: \(location)")
118+
print("Did end swiping view at location: \(location)")
67119
}
68120
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)")
70122
}
71123
swipeableView.didCancel = {view in
72-
println("Did cancel swiping view")
124+
print("Did cancel swiping view")
73125
}
74126
~~~
75127

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.
77-
~~~swift
78-
swipeableView.swipeTopView(inDirection: .Left)
79-
swipeableView.swipeTopView(inDirection: .Up)
80-
swipeableView.swipeTopView(inDirection: .Right)
81-
swipeableView.swipeTopView(inDirection: .Down)
82128

83-
swipeableView.swipeTopView(fromPoint: CGPoint(x: 100, y: 30), inDirection: CGVector(dx: 100, dy: -800))
129+
### Customization
130+
Here is a list of customizable behaviors:
131+
~~~swift
132+
public var animateView = ZLSwipeableView.defaultAnimateViewHandler()
133+
public var interpretDirection = ZLSwipeableView.defaultInterpretDirectionHandler()
134+
public var shouldSwipeView = ZLSwipeableView.defaultShouldSwipeViewHandler()
135+
public var minTranslationInPercent = CGFloat(0.25)
136+
public var minVelocityInPointPerSecond = CGFloat(750)
137+
public var allowedDirection = Direction.Horizontal
84138
~~~
85-
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.
86139

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
87144
You can create custom animation by overriding the `animateView` property. Take a look at the [Custom Animation](#custom-animation) example for details.
88145

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.
151+
~~~swift
152+
swipeableView.allowedDirection = .Left | .Up
153+
swipeableView.allowedDirection = .All
154+
~~~
155+
156+
### Misc
157+
158+
~~~swift
159+
public func topView() -> UIView?
160+
161+
public func activeViews() -> [UIView]
162+
~~~
90163

91164
Requirements
92165
---

0 commit comments

Comments
 (0)