-
-
Save alemar11/8a1f15da4961531081362d6ac456831b to your computer and use it in GitHub Desktop.
NotchFix - source code for https://twitter.com/vojtastavik/status/907911237983449088
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
| @IBOutlet weak var tableView: UITableView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| NSLayoutConstraint.activate([ | |
| tableView.topAnchor.constraint(equalTo: view.topAnchor), | |
| tableView.leftAnchor.constraint(equalTo: view.leftAnchor), | |
| tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), | |
| tableView.rightAnchor.constraint(equalTo: view.rightAnchor), | |
| ]) | |
| } | |
| let names = ["John", "Paul", "George", "Ringo"] | |
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| return 100 | |
| } | |
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) | |
| cell.textLabel!.text = names[indexPath.row % 4] | |
| return cell | |
| } | |
| func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
| for cell in tableView.visibleCells { | |
| let y = tableView.convert(cell.frame.origin, to: view).y | |
| UIView.animate(withDuration: 0.2) { | |
| if y > 40 && y < 280 { | |
| if cell.transform == .identity { | |
| cell.transform = .init(translationX: 40, y: 0) | |
| } | |
| } else { | |
| cell.transform = .identity | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment