forked from SwipeCellKit/SwipeCellKit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSwipeCollectionViewCell+Display.swift
55 lines (42 loc) · 2.55 KB
/
SwipeCollectionViewCell+Display.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// SwipeCollectionViewCell+Display.swift
//
// Created by Jeremy Koch
// Copyright © 2017 Jeremy Koch. All rights reserved.
//
import UIKit
extension SwipeCollectionViewCell {
/// The point at which the origin of the cell is offset from the non-swiped origin.
public var swipeOffset: CGFloat {
set { setSwipeOffset(newValue, animated: false) }
get { return contentView.frame.midX - bounds.midX }
}
/**
Hides the swipe actions and returns the cell to center.
- parameter animated: Specify `true` to animate the hiding of the swipe actions or `false` to hide it immediately.
- parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
*/
public func hideSwipe(animated: Bool, completion: ((Bool) -> Void)? = nil) {
swipeController.hideSwipe(animated: animated, completion: completion)
}
/**
Shows the swipe actions for the specified orientation.
- parameter orientation: The side of the cell on which to show the swipe actions.
- parameter animated: Specify `true` to animate the showing of the swipe actions or `false` to show them immediately.
- parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
*/
public func showSwipe(orientation: SwipeActionsOrientation, animated: Bool = true, completion: ((Bool) -> Void)? = nil) {
setSwipeOffset(.greatestFiniteMagnitude * orientation.scale * -1,
animated: animated,
completion: completion)
}
/**
The point at which the origin of the cell is offset from the non-swiped origin.
- parameter offset: A point (expressed in points) that is offset from the non-swiped origin.
- parameter animated: Specify `true` to animate the transition to the new offset, `false` to make the transition immediate.
- parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
*/
public func setSwipeOffset(_ offset: CGFloat, animated: Bool = true, completion: ((Bool) -> Void)? = nil) {
swipeController.setSwipeOffset(offset, animated: animated, completion: completion)
}
}