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
ScrollStackController was created and maintaned by [Daniele Margutti](https://twitter.com/danielemargutti) › [Web Site](https://www.danielemargutti.com)
11
12
@@ -18,12 +19,23 @@ You can think of it as `UITableView` but with several differences:
18
19
-**Powered by AutoLayout since the beginning**; it uses a combination of `UIScrollView + UIStackView` to offer an animation friendly controller ideal for fixed and dynamic row sizing.
19
20
-**You don't need to struggle yourself with view recycling**: suppose you have a layout composed by several different screens. There is no need of view recycling but it cause a more difficult managment of the layout. With a simpler and safer APIs set `ScrollStackView` is the ideal way to implement such layouts.
### When to use `ScrollStackController` and when not
@@ -82,6 +75,8 @@ If you have a long list of rows you may experience delays.
82
75
83
76
So, `ScrollStackController` is generally not appropriate for screens that contain many views of the same type, all showing similar data (in these cases you should use `UITableView` or `UICollectionView`).
@@ -90,7 +85,16 @@ So, `ScrollStackController` is generally not appropriate for screens that contai
90
85
91
86
The main class of the package is `ScrollStack`, a subclass of `UIScrollView`. It manages the layout of each row, animations and keep a strong reference to your rows.
92
87
93
-
However usually you don't want to intantiate this control directly but by calling the `ScrollStackController` class.
88
+
This is an overview of the architecture:
89
+
90
+

91
+
92
+
-`ScrollStackController `: is a subclass of `UIViewController`. You would to use it and add as a child controller of your view controller. This allows you to manage any child-controllers related events for each row you will add to the stack controller.
93
+
-`ScrollStack`: the view of the `ScrollStackController ` is a `ScrollStack`, a subclass of `UIScrollView` with an `UIStackView` which allows you to manage the layout of the stack. You can access to it via `scrollStack` property of the controller.
94
+
- Each row is a `ScrollStackRow`, which is a subclass of `UIView`. Inside there are two views, the `contentView` (a reference to managed `UIViewController`'s `view`) and the `separatorView`. A row strongly reference managed view controller, so you don't need to keep a strong reference by your own.
95
+
- Separator view are subclass of `ScrollStackSeparator` class.
96
+
97
+
As we said, usually you don't want to intantiate a `ScrollStack` control directly but by using the `ScrollStackController` class.
94
98
It's a view controller which allows you to get the child view controller's managment for free, so when you add/remove a row to the stack you will get the standard UIViewController events for free!
95
99
96
100
This is an example of initialization in a view controller:
@@ -102,6 +106,8 @@ class MyViewController: UIViewController {
102
106
103
107
overridefuncviewDidLoad() {
104
108
super.viewDidLoad()
109
+
110
+
stackController.view.frame= contentView.bounds
105
111
contentView.addSubview(stackController.view)
106
112
}
107
113
@@ -111,7 +117,7 @@ class MyViewController: UIViewController {
111
117
Now you are ready to use the `ScrollStack` control inside the `stackController` class.
112
118
`ScrollStack` have an extensible rich set of APIs to manage your layout: add, remove, move, hide or show your rows, including insets and separator management.
113
119
114
-
Each row managed by `ScrollStack` is a subclass of `ScrollStackRow`: it strongly reference a parent `UIViewController` class where you content is placed. `UIViewController`'s `view` will be the `contentView` of the row.
120
+
Each row managed by `ScrollStack` is a subclass of `ScrollStackRow`: it strongly reference a parent `UIViewController` class where you content is placed. `UIViewController`'s `view` will be the `contentView` of the row itself.
115
121
116
122
You don't need to handle lifecycle of your rows/view controller until they are part of the rows inside the stack.
@@ -470,14 +476,126 @@ Transition between highlights state will be animated automatically.
470
476
471
477
[↑ Back To Top](#index)
472
478
479
+
<aname="utilsmethods"/>
480
+
481
+
### Get the row/controller
482
+
483
+
**Get the (first) row which manage a specific view controller type**
484
+
You can get the first row which manage a specific view controller class using `firstRowForControllerOfType<T: UIViewController>(:) -> ScrollStackRow?` function.
485
+
486
+
```swift
487
+
let tagsVC = scrollStack.firstRowForControllerOfType(TagsVC.self) // TagsVC instance
488
+
```
489
+
490
+
**Get the row which manage a specific controller instance**
491
+
To get the row associated with a specific controller you can use `rowForController()` function:
492
+
493
+
```swift
494
+
let row = scrollStack.rowForController(tagsVC) // ScrollStackRow
495
+
```
496
+
497
+
<aname="setrowinsets"/>
498
+
499
+
### Set Row Insets
500
+
501
+
To set an insets for a specific row you can use `setRowInsets()` function:
You can also use `setRowsInsets()` to set multiple rows.
509
+
510
+
Moreover by setting `.rowInsets` in your `ScrollStack` class you can set a default insets value for new row added.
511
+
512
+
<aname="changescrollaxis"/>
513
+
514
+
### Change ScrollStack scrolling axis
515
+
516
+
In order to change the axis of scroll for your `ScrollStack` instances you can set the `axis` property to `horizontal` or `vertical.
517
+
518
+
<aname="rowevents"/>
519
+
520
+
### Subscribe to Row Events
521
+
522
+
You can listen when a row is removed or added into the stack view by subscribing the `onChangeRow` property.
523
+
524
+
```swift
525
+
scrollStackView.onChangeRow= { (row, isRemoved) in
526
+
if isRemoved {
527
+
print("Row at index \(row.index) was removed"
528
+
} else {
529
+
print("A new row is added at index: \(row.index). It manages \(type(of: row.controller))")
530
+
}
531
+
}
532
+
```
533
+
534
+
You can also subscribe events for events about row visibility state changes by setting the `stackDelegate`. Your destination object must therefore conforms to the `ScrollStackControllerDelegate ` protocol:
535
+
536
+
Example:
537
+
538
+
```swift
539
+
class ViewController: ScrollStackController, ScrollStackControllerDelegate {
// Row did become partially or entirely invisible.
557
+
}
558
+
559
+
}
560
+
```
561
+
562
+
`ScrollStack.RowVisibility` is an enum with the following cases:
563
+
564
+
- `partial`: row is partially visible.
565
+
- `entire`: row is entirely visible.
566
+
- `hidden`: row is invisible and hidden.
567
+
- `offscreen`: row is not hidden but currently offscreen due to scroll position.
568
+
569
+
[↑ Back To Top](#index)
570
+
571
+
<a name="systemrequirements"/>
572
+
573
+
### System Requirements
574
+
575
+
- iOS 11+
576
+
- Xcode 10+
577
+
- Swift 5+
578
+
579
+
[↑ Back To Top](#index)
580
+
581
+
<a name="exampleapp"/>
582
+
583
+
### Example App
584
+
585
+
`ScrollStackController` comes with a demo application which show how easy you can create complex scrollable layoyut and some of the major features of the library.
586
+
587
+
You should look at it in order to implement your own layout, create dynamically sized rows and dispatch events.
588
+
589
+
[↑ Back To Top](#index)
590
+
473
591
<a name="installation"/>
474
592
475
593
### Installation
476
594
477
-
`ScrollStackContainer` can be installed with CocoaPods by adding pod 'ScrollStackContainer' to your Podfile.
595
+
`ScrollStackController` can be installed with CocoaPods by adding pod 'ScrollStackController' to your Podfile.
478
596
479
597
```ruby
480
-
pod 'ScrollStackContainer'
598
+
pod 'ScrollStackController'
481
599
```
482
600
483
601
It also supports `Swift Package Maneger` aka SPM.
@@ -488,15 +606,18 @@ It also supports `Swift Package Maneger` aka SPM.
488
606
489
607
### Author & License
490
608
491
-
`ScrollStackContainer` is developed and maintained by:
609
+
`ScrollStackController` is developed and maintained by:
492
610
493
611
- Daniele Margutti ([danielemargutti.com](http://www.danielemargutti.com) - [@danielemargutti](http://www.twitter.com/danielemargutti) on twitter)
494
612
495
613
I fully welcome contributions, new features, feature requests, bug reports, and fixes. Also PR are accepted!
496
614
497
-
`ScrollStackContainer` is released under the MIT License.
615
+
`ScrollStackController` is released under the MIT License.
616
+
617
+
The following library was originally inspired by two great works:
498
618
499
-
It was originally inspired by [`AloeStackView`](https://github.com/airbnb/AloeStackView) by Airbnb.
619
+
- [`AloeStackView`](https://github.com/airbnb/AloeStackView) by the engineering team at AirBnb
620
+
- [`ScrollingStackViewController`](https://github.com/justeat/ScrollingStackViewController) by the engineering team at JustEat
0 commit comments