OK, so an app I'm working on is going to have a dictionary-like section, and I'm trying to set it up so the user can swipe to see the next/previous without having to add next/previous buttons to the layout or send the user back to the main UITableView
to choose another row.
I'm working on building out the UI at the moment, and I've got a 90% solution to what I'm trying to do for that view here:
import UIKit
class CharacterDetailViewController: UIViewController, UIGestureRecognizerDelegate, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
title = "Character Detail View"
// Disable swipe-to-pop gesture
navigationController?.interactivePopGestureRecognizer?.delegate = self
navigationController?.interactivePopGestureRecognizer?.isEnabled = false
// Detect swipe gesture to load next entry
view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(swipeNextEntry)))
}
@objc func swipeNextEntry(_ sender: UIPanGestureRecognizer) {
print("[DEBUG] Pan Gesture Detected")
if (sender.state == .ended) {
let velocity = sender.velocity(in: self.view)
guard let vc = storyboard?.instantiateViewController(identifier: "CharacterDetail") else { return }
if (velocity.x > 0) { // Coming from left
navigationController?.pushViewController(vc, animated: true)
} else { // Coming from right
navigationController?.pushViewController(vc, animated: true)
}
}
}
}
The issue I'm having is that no matter which direction you swipe from, the new view controller always comes in from the right side of the screen. I've been trying to figure out how to make new controller push in from the left side instead, and I'm not getting very far. I saw something earlier suggesting using a segue to configure how the new views appear, but IB won't allow you to set something to segue to itself from what I can tell.
Any thoughts on how to proceed? Thanks!