Skip to content

Commit 8ea817a

Browse files
committed
Add scroll
1 parent 40e06e5 commit 8ea817a

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Cartfile.private

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
github "devxoul/Then"
2+
github "nakiostudio/EasyPeasy"

Cartfile.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "nakiostudio/EasyPeasy" "a79e0d1c48d42cc1a28ea95e9fd8b924dfbea8a8"
2-
github "devxoul/Then" "2.0.0"
1+
github "nakiostudio/EasyPeasy" "1.4.1"
2+
github "devxoul/Then" "2.1.0"

StackScrollView/StackScrollView.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
6060
register(Cell.self, forCellWithReuseIdentifier: "Cell")
6161
alwaysBounceVertical = true
6262
delaysContentTouches = false
63-
keyboardDismissMode = .onDrag
63+
keyboardDismissMode = .interactive
6464
backgroundColor = .white
6565

6666
delegate = self
@@ -95,6 +95,12 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
9595
scrollRectToVisible(targetRect, animated: true)
9696
}
9797

98+
open func scroll(to view: UIView, at position: UICollectionViewScrollPosition, animated: Bool) {
99+
if let index = views.index(of: view) {
100+
scrollToItem(at: IndexPath(item: index, section: 0), at: position, animated: animated)
101+
}
102+
}
103+
98104
open override func touchesShouldCancel(in view: UIView) -> Bool {
99105
return true
100106
}
@@ -203,6 +209,9 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
203209
}
204210

205211
final class Cell: UICollectionViewCell {
206-
212+
213+
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
214+
return layoutAttributes
215+
}
207216
}
208217
}

StackScrollView/StackScrollViewCellType.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extension StackScrollViewCellType where Self: UIView {
4343
stackScrollView?.scroll(to: self, animated: animated)
4444
}
4545

46+
public func scrollToSelf(at position: UICollectionViewScrollPosition, animated: Bool) {
47+
stackScrollView?.scroll(to: self, at: position, animated: animated)
48+
}
49+
4650
public func updateLayout(animated: Bool) {
4751
invalidateIntrinsicContentSize()
4852
stackScrollView?.updateLayout(animated: animated)

0 commit comments

Comments
 (0)