|
1 |
| -# ScrollingStackContainer |
2 |
| -Scrolling stack-view container |
| 1 | +<p align="center" > |
| 2 | +<img src="https://raw.githubusercontent.com/malcommac/ScrollingStackContainer/develop/logo.png" width=300px height=197px alt="ScrollingStackContainer" title="ScrollingStackContainer"> |
| 3 | +</p> |
| 4 | + |
| 5 | +[](https://github.com/Carthage/Carthage) [](https://travis-ci.org/malcommac/ScrollingStackContainer) [](http://cocoadocs.org/docsets/ScrollingStackContainer) [](http://cocoadocs.org/docsets/ScrollingStackContainer) [](http://cocoadocs.org/docsets/ScrollingStackContainer) |
| 6 | + |
| 7 | +<p align="center" >★★ <b>Star our github repository to help us!</b> ★★</p> |
| 8 | +<p align="center" >Created by <a href="http://www.danielemargutti.com">Daniele Margutti</a> (<a href="http://www.twitter.com/danielemargutti">@danielemargutti</a>)</p> |
| 9 | + |
| 10 | +`ScrollingStackContainer` is an efficient scrolling `UIStackView` replacement, more suitable in situations when you are building a scrolling container with an heterogeneous number of items. |
| 11 | +It allows you to stack vertically `UIViewController` instances where the view is a simple fixed-height `UIView` or a `UICollectionView` or `UITableView`. |
| 12 | + |
| 13 | +## Motivation |
| 14 | +A full article about the motivation behind this class is available on Medium (or in my personal blog). Check it here for full details about how the class works. |
| 15 | + |
| 16 | +UITableView and UICollectionView are great when you need to display a number of relatively simple cells; when your layout became complex you may need to create different UIViewController which manages each different kind layout. |
| 17 | +These view controller may contains simple fixed-height `UIView` or complex `UICollectionView`/`UITableView`; in these cases you need to be careful because expading your scrollviews will destroy internal iOS caching mechanism. |
| 18 | +`ScrollingStackContainer` allows you to stack view controllers easily without any worry; it manages view controllers with scrolling collections automatically in order to reduce the amount of memory usage. |
| 19 | + |
| 20 | +## How to use it |
| 21 | + |
| 22 | +It's very simple to implement: for **fixed height views** you should set a valid `height` (grater than zero). This can be done in your `UIViewController`'s subclass in one of the following ways: |
| 23 | + |
| 24 | +* set an height constraint on `UIViewController`’s .view |
| 25 | +* … or return a value into `preferredContentSize()` function |
| 26 | +* … or set the height via `self.frame` |
| 27 | +* … or by implementing the `StackContainable` protocol and returning `.view(height: <height>)` with a valid value. |
| 28 | + |
| 29 | +For view controllers which **contains inner’s scroll views** (for example table or collections) you need to implement the `StackContainble` protocol by returning `.scroll(<inner scroll instance>, <insets of the inner scroll in superview>)`. |
| 30 | + |
| 31 | +After that you should simply set the `viewControllers` property of your `ScrollingStackContainer` subclass: |
| 32 | + |
| 33 | +```swift |
| 34 | + // view controller's view are stacked vertically in order |
| 35 | + self.viewControllers = [controller_2,controller_1,controller_3] |
| 36 | +``` |
| 37 | + |
| 38 | +That’s all! All the business logic is managed by the class and you can enjoy! |
| 39 | + |
| 40 | +See the example in this repository to get a live preview! |
| 41 | + |
| 42 | +The following example is a vertical stack which contains a fixed height view controller, a view controller with a table inside and another fixed height controller. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +## You also may like |
| 47 | + |
| 48 | +Do you like `ScrollingStackContainer`? I'm also working on several other opensource libraries. |
| 49 | + |
| 50 | +Take a look here: |
| 51 | + |
| 52 | +* **[Hydra](https://github.com/malcommac/Hydra)** - Promises & Await/Async in Swift - Write better async code in Swift |
| 53 | +* **[SwiftLocation](https://github.com/malcommac/SwiftLocation)** - CoreLocation and Beacon Monitoring on steroid! |
| 54 | +* **[SwiftRichString](https://github.com/malcommac/SwiftRichString)** - Elegant and painless attributed string in Swift |
| 55 | +* **[SwiftScanner](https://github.com/malcommac/SwiftScanner)** - String scanner in pure Swift with full unicode support |
| 56 | +* **[SwiftSimplify](https://github.com/malcommac/SwiftSimplify)** - Tiny high-performance Swift Polyline Simplification Library |
| 57 | +* **[SwiftMsgPack](https://github.com/malcommac/SwiftMsgPack)** - MsgPack Encoder/Decoder in Swit |
| 58 | + |
| 59 | +## Installation |
| 60 | + |
| 61 | +`ScrollingStackContainer` supports multiple methods for installing the library in a project. |
| 62 | + |
| 63 | +## Installation with CocoaPods |
| 64 | + |
| 65 | +[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like `ScrollingStackContainer` in your projects. You can install it with the following command: |
| 66 | + |
| 67 | +```bash |
| 68 | +$ gem install cocoapods |
| 69 | +``` |
| 70 | + |
| 71 | +#### Podfile |
| 72 | + |
| 73 | +To integrate ScrollingStackContainer into your Xcode project using CocoaPods, specify it in your `Podfile`: |
| 74 | + |
| 75 | +```ruby |
| 76 | +source 'https://github.com/CocoaPods/Specs.git' |
| 77 | +platform :ios, '8.0' |
| 78 | + |
| 79 | +target 'TargetName' do |
| 80 | +use_frameworks! |
| 81 | +pod 'ScrollingStackContainer', '~> 0.5' |
| 82 | +end |
| 83 | +``` |
| 84 | + |
| 85 | +Then, run the following command: |
| 86 | + |
| 87 | +```bash |
| 88 | +$ pod install |
| 89 | +``` |
| 90 | + |
| 91 | +### Installation with Carthage |
| 92 | + |
| 93 | +[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. |
| 94 | + |
| 95 | +You can install Carthage with [Homebrew](http://brew.sh/) using the following command: |
| 96 | + |
| 97 | +```bash |
| 98 | +$ brew update |
| 99 | +$ brew install carthage |
| 100 | +``` |
| 101 | + |
| 102 | +To integrate ScrollingStackContainer into your Xcode project using Carthage, specify it in your `Cartfile`: |
| 103 | + |
| 104 | +```ogdl |
| 105 | +github "malcommac/ScrollingStackContainer" ~> 0.5 |
| 106 | +``` |
| 107 | + |
| 108 | +Run `carthage` to build the framework and drag the built `ScrollingStackContainer.framework` into your Xcode project. |
| 109 | + |
| 110 | +## Requirements |
| 111 | + |
| 112 | +Current version is compatible with: |
| 113 | + |
| 114 | +* Swift 3.1 |
| 115 | +* iOS 8 or later |
| 116 | +* ...and virtually any platform which is compatible with Swift 3 and implements the Swift Foundation Library |
| 117 | + |
| 118 | + |
| 119 | +## Credits & License |
| 120 | +ScrollingStackContainer is owned and maintained by [Daniele Margutti](http://www.danielemargutti.com/) along with main contributions of [Jeroen Houtzager](https://github.com/Hout). |
| 121 | + |
| 122 | +As open source creation any help is welcome! |
| 123 | + |
| 124 | +The code of this library is licensed under MIT License; you can use it in commercial products without any limitation. |
0 commit comments