-
Notifications
You must be signed in to change notification settings - Fork 277
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
Dismiss detail view controller by scrolling on content #107
Comments
Actually, I don't think so. |
I can’t seem to figure out how to do what you said above? Do you have any example code that can achieve this? |
Forgive me if I have expressed myself badly, english isn't my first language. // Line 176 //MARK: - ScrollView Behaviour
extension DetailViewController: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
let y = scrollView.contentOffset.y
let offset = scrollView.frame.origin.y - scrollViewOriginalYPosition
// Behavior when scroll view is pulled down
if (y<0) {
scrollView.frame.origin.y -= y/2
scrollView.contentOffset.y = 0
// Behavior when scroll view is pulled down and then up
} else if ( offset > 0) {
scrollView.contentOffset.y = 0
scrollView.frame.origin.y -= y/2
}
card.delegate?.cardDetailIsScrolling?(card: card)
}
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let offset = scrollView.frame.origin.y - scrollViewOriginalYPosition
// Pull down speed calculations
let max = 4.0
let min = 2.0
var speed = Double(-velocity.y)
if speed > max { speed = max }
if speed < min { speed = min }
speed = (max/speed*min)/10
guard offset < 60 else { dismissVC(); return }
guard offset > 0 else { return }
// Come back after pull animation
UIView.animate(withDuration: speed, animations: {
scrollView.frame.origin.y = self.scrollViewOriginalYPosition
self.scrollView.contentOffset.y = 0
})
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let offset = scrollView.frame.origin.y - scrollViewOriginalYPosition
guard offset > 0 else { return }
// Come back after pull animation
UIView.animate(withDuration: 0.1, animations: {
scrollView.frame.origin.y = self.scrollViewOriginalYPosition
self.scrollView.contentOffset.y = 0
})
}
} Some tips: |
OK because I am trying t get the card animation to look exactly like that on the app store where you can only dismiss the detail view controller by scrolling on the image view, no the whole content because then the user can easily/accidentally dismiss the view controller. |
Is there a way to dismiss the detail view controller only by performing a gesture on the image view rather than the whole content of the detail view controller?
The text was updated successfully, but these errors were encountered: