https://github.com/marty-suzuki/splittableviewkit
A cell of IndexPath(row: 0, section: 0) in UITableView is automatically moved to left view when device rotated.
https://github.com/marty-suzuki/splittableviewkit
orientation rotation split swift tableview
Last synced: 2 months ago
JSON representation
A cell of IndexPath(row: 0, section: 0) in UITableView is automatically moved to left view when device rotated.
- Host: GitHub
- URL: https://github.com/marty-suzuki/splittableviewkit
- Owner: marty-suzuki
- License: mit
- Created: 2018-10-21T01:41:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T16:23:59.000Z (over 6 years ago)
- Last Synced: 2025-03-26T14:50:55.391Z (3 months ago)
- Topics: orientation, rotation, split, swift, tableview
- Language: Swift
- Homepage:
- Size: 27.7 MB
- Stars: 37
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SplittableViewKit
[](https://developer.apple.com/swift)
[](https://github.com/Carthage/Carthage)
[](https://cocoapods.org/pods/SplittableViewKit)
[](https://cocoapods.org/pods/SplittableViewKit)
[](https://cocoapods.org/pods/SplittableViewKit)A cell of `IndexPath(row: 0, section: 0)` in UITableView is automatically moved to left view when device rotated.

## Usage
Please initialize `SplittableTableView` with initializer or Interface Builder.
`SplittableTableView.rightView` is UITableView.
Do not set delegate or dataSource directly to `SplittableTableView.rightView`.
You must use `SplittableTableView.delgate` or `SplittableTableView.dataSource`.```swift
let splittableTableView: SplittableTableViewsplittableTableView.delegate = self
splittableTableView.dataSource = self
splittableTableView.rightView.register(UINib(nibName: "ThumbnailViewCell", bundle: nil),
forCellReuseIdentifier: "ThumbnailViewCell")
```SplittableViewKit is almost same as UITableView interface because `SplittableTableViewDataSource` adopted UITableViewDataSource and `SplittableTableViewDelegate` adopted UITableViewDelegate.
`func splittableContainerViewFor(topView: UIView, layoutType: LayoutType) -> UIView` is only one difference.
You should return a UIView that layouted top view. Layout patterns are `LayoutType.left` and `LayoutType.fixedTop`.```swift
extension ViewController: SplittableTableViewDataSource {
func splittableContainerViewFor(topView: UIView, layoutType: LayoutType) -> UIView {
let view = UIView(frame: .zero)
topView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(topView)
if layoutType == .left {
NSLayoutConstraint.activate([
view.leadingAnchor.constraint(equalTo: topView.leadingAnchor, constant: 0),
view.trailingAnchor.constraint(equalTo: topView.trailingAnchor, constant: 0),
view.centerYAnchor.constraint(equalTo: topView.centerYAnchor, constant: 0)
])
} else {
NSLayoutConstraint.activate([
view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: topView.topAnchor, constant: 0),
view.leftAnchor.constraint(equalTo: topView.leftAnchor, constant: 0),
view.rightAnchor.constraint(equalTo: topView.rightAnchor, constant: 0),
view.bottomAnchor.constraint(equalTo: topView.bottomAnchor, constant: 0)
])
}
return view
}
}
```You can change fixed top or not with `SplittableTableView.isFixedTop`.
```swift
splittableTableView.isFixedTop = true
```| left | fixedTop |
| :-: | :-: |
|  |  |You can change ratio of leftView and rightView with `SplittableTableView.ratio`.
```swift
splittableTableView.ratio = .init(left: 1, right: 2)
```| left: 1, right: 1 | left: 2, right: 1 |
| :-: | :-: |
|  |  |## Example
To run the example project, clone the repo, and run `pod install` from the `SplittableViewKitExample` directory first.
## Requirements
- iOS 9 or greater
- Swift 4 or greater## Installation
### Carthage
If you’re using [Carthage](https://github.com/Carthage/Carthage), simply add SplittableViewKit to your `Cartfile`:
```ruby
github "marty-suzuki/SplittableViewKit"
```### CocoaPods
SplittableViewKit is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'SplittableViewKit'
```## Author
marty-suzuki, [email protected]
## License
SplittableViewKit is available under the MIT license. See the LICENSE file for more info.