@@ -33,10 +33,10 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
3333 }
3434
3535 open var views : [ UIView ] {
36- return source. map { $0 . 0 }
36+ return source
3737 }
3838
39- private var source : [ ( UIView , String ) ] = [ ]
39+ private var source : [ UIView ] = [ ]
4040
4141 public convenience init ( ) {
4242 self . init ( frame: . zero)
@@ -73,11 +73,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
7373
7474 open func append( view: UIView ) {
7575
76- let key = UUID ( ) . uuidString
77- source. append ( ( view, key) )
78-
79- register ( Cell . self, forCellWithReuseIdentifier: key)
80-
76+ source. append ( view)
8177 reloadData ( )
8278 }
8379
@@ -91,9 +87,36 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
9187
9288 open func remove( view: UIView , animated: Bool ) {
9389
94- if let index = source. map ( { $0 . 0 } ) . index ( of: view) {
90+ if let index = source. index ( of: view) {
9591 source. remove ( at: index)
96- view. removeFromSuperview ( )
92+ if animated {
93+ UIView . animate (
94+ withDuration: 0.5 ,
95+ delay: 0 ,
96+ usingSpringWithDamping: 1 ,
97+ initialSpringVelocity: 0 ,
98+ options: [
99+ . beginFromCurrentState,
100+ . allowUserInteraction,
101+ . overrideInheritedCurve,
102+ . overrideInheritedOptions,
103+ . overrideInheritedDuration
104+ ] ,
105+ animations: {
106+ self . performBatchUpdates ( {
107+ self . deleteItems ( at: [ IndexPath . init ( item: index, section: 0 ) ] )
108+ } , completion: nil )
109+ } ) { ( finish) in
110+
111+ }
112+
113+ } else {
114+ UIView . performWithoutAnimation {
115+ performBatchUpdates ( {
116+ self . deleteItems ( at: [ IndexPath . init ( item: index, section: 0 ) ] )
117+ } , completion: nil )
118+ }
119+ }
97120 }
98121 }
99122
@@ -104,7 +127,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
104127 }
105128
106129 open func scroll( to view: UIView , at position: UICollectionViewScrollPosition , animated: Bool ) {
107- if let index = source. map ( { $0 . 0 } ) . index ( of: view) {
130+ if let index = source. index ( of: view) {
108131 scrollToItem ( at: IndexPath ( item: index, section: 0 ) , at: position, animated: animated)
109132 }
110133 }
@@ -123,9 +146,9 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
123146
124147 public func collectionView( _ collectionView: UICollectionView , cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
125148
126- let cell = collectionView. dequeueReusableCell ( withReuseIdentifier: source [ indexPath . item ] . 1 , for: indexPath)
149+ let cell = collectionView. dequeueReusableCell ( withReuseIdentifier: " Cell " , for: indexPath)
127150
128- let view = source [ indexPath. item] . 0
151+ let view = source [ indexPath. item]
129152
130153 if view. superview == cell. contentView {
131154 return cell
@@ -163,7 +186,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
163186
164187 public func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , sizeForItemAt indexPath: IndexPath ) -> CGSize {
165188
166- let view = source [ indexPath. item] . 0
189+ let view = source [ indexPath. item]
167190
168191 let width : NSLayoutConstraint = {
169192
0 commit comments