New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table view scroll #10
Comments
UITableView is a subclass of UIScrollView. So I think you will have to implement the dismissal code too. Please note: I haven't tried this myself but I think this will work.
|
I have and it didn’t work.
On Thu, Jun 8, 2017 at 2:03 PM -0400, "Anmol Malhotra" <notifications@github.com> wrote:
UITableView is a subclass of UIScrollView. So I think you will have to implement the dismissal code too.
Have you tried this one (the one written in description):
Please note: I haven't tried this myself but I think this will work.
`func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView.isEqual(textView) else {
return
}
if let delegate = transitioningDelegate as? DeckTransitioningDelegate {
if scrollView.contentOffset.y > 0 {
// Normal behaviour if the `scrollView` isn't scrolled to the top
scrollView.bounces = true
delegate.isDismissEnabled = false
} else {
if scrollView.isDecelerating {
// If the `scrollView` is scrolled to the top but is decelerating
// that means a swipe has been performed. The view and scrollview are
// both translated in response to this.
view.transform = CGAffineTransform(translationX: 0, y: -scrollView.contentOffset.y)
scrollView.transform = CGAffineTransform(translationX: 0, y: scrollView.contentOffset.y)
} else {
// If the user has panned to the top, the scrollview doesnʼt bounce and
// the dismiss gesture is enabled.
scrollView.bounces = false
delegate.isDismissEnabled = true
}
}
}
}`
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Hi there @CTKRocks. The code in the README should work as expected for you, provided you just replace the I could take a look at your code if you could share it, since I can’t really gauge much just from the description alone. |
Closing due to inactivity |
The code in the Readme does not work. |
At least for TableView |
The code as it is does work with //
// ModalViewController.swift
// DeckTransition
//
// Created by Harshil Shah on 15/10/16.
// Copyright © 2016 Harshil Shah. All rights reserved.
//
import UIKit
import DeckTransition
class ModalViewController: UIViewController, UITableViewDelegate {
let tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
modalPresentationCapturesStatusBarAppearance = true
view.backgroundColor = .white
tableView.showsVerticalScrollIndicator = false
tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView)
tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true
tableView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 20).isActive = true
tableView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20).isActive = true
tableView.bounces = false
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
tableView.dataSource = self
tableView.delegate = self
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView.isEqual(tableView) else {
return
}
if let delegate = transitioningDelegate as? DeckTransitioningDelegate {
if scrollView.contentOffset.y > 0 {
scrollView.bounces = true
delegate.isDismissEnabled = false
} else {
if scrollView.isDecelerating {
view.transform = CGAffineTransform(translationX: 0, y: -scrollView.contentOffset.y)
scrollView.subviews.forEach {
$0.transform = CGAffineTransform(translationX: 0, y: scrollView.contentOffset.y)
}
} else {
scrollView.bounces = false
delegate.isDismissEnabled = true
}
}
}
}
}
extension ModalViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = "This is cell number \(indexPath.row)"
return cell
}
} |
Hmmm. Strange. For me using the code with my tableView replacing the textView does not work. |
Updated my comment above. You can check for yourself |
No. That code is not working for my case. Here's my code: override func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView.isEqual(self.tableView) else {
return
}
if let delegate = transitioningDelegate as? DeckTransitioningDelegate {
if scrollView.contentOffset.y > 0 {
scrollView.bounces = true
delegate.isDismissEnabled = false
} else {
if scrollView.isDecelerating {
view.transform = CGAffineTransform(translationX: 0, y: -scrollView.contentOffset.y)
scrollView.subviews.forEach {
$0.transform = CGAffineTransform(translationX: 0, y: scrollView.contentOffset.y)
}
} else {
scrollView.bounces = false
delegate.isDismissEnabled = true
}
}
}
} |
My point was the code works for |
The override there means your view controller's superclass is implementing its own |
I have implemented your scroll view code to my table view controller and it will dismiss when I’m not at the top. Do you have any suggestions?
Also when it said set the scroll view delegate as self, I just made sure tableview.delegate equaled self. Is that correct?
The text was updated successfully, but these errors were encountered: