An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# SplittableViewKit

[![Language](http://img.shields.io/badge/Language-Swift-orange.svg?style=flat
)](https://developer.apple.com/swift)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Version](https://img.shields.io/cocoapods/v/SplittableViewKit.svg?style=flat)](https://cocoapods.org/pods/SplittableViewKit)
[![License](https://img.shields.io/cocoapods/l/SplittableViewKit.svg?style=flat)](https://cocoapods.org/pods/SplittableViewKit)
[![Platform](https://img.shields.io/cocoapods/p/SplittableViewKit.svg?style=flat)](https://cocoapods.org/pods/SplittableViewKit)

A cell of `IndexPath(row: 0, section: 0)` in UITableView is automatically moved to left view when device rotated.

![](./Images/sample.gif)

## 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: SplittableTableView

splittableTableView.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 |
| :-: | :-: |
| ![](./Images/normal.gif) | ![](./Images/fixed.gif) |

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 |
| :-: | :-: |
| ![](./Images/one-one.png) | ![](./Images/two-one.png) |

## 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.