I'm doing my first custom segue animations. What I want is to have a list view that when I select on a row, instead of sliding in from the side, it expands in place from the row selected. Something like:
So the user selects the green row, which causes the new controller to start at the green row size and expand to fill the screen. This part has worked fine so far.
The problem I'm having is with the unwind segue which seeks to do the opposite, shrink the full screen back to the original row and then dismiss. What happens is that it shrinks fine, but the area exposed remains black, and then suddenly flashes into place when the animation is done. What is wanted is something like this:
But what is happening is more like this:
The code I'm using for the unwind's perform
looks like:
class FromScheduleFocusSegue: UIStoryboardSegue {
override func perform() {
let fromView = self.source.view!
let toView = self.destination.view!
let window = UIApplication.shared.keyWindow!
let schedulesList = self.destination as! SchedulesListController
let cell = schedulesList.tableView.cellForRow(at: schedulesList.tableView.indexPathForSelectedRow!)!
var stripe = cell.bounds
stripe.size.height = 60
let targetFrame = cell.convert(stripe, to: window).insetBy(dx: 0, dy: 0)
schedulesList.tableView.selectRow(at: nil, animated: false, scrollPosition: .none)
UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
fromView.frame = targetFrame
}) { (finished) in
self.source.dismiss(animated: false, completion: nil)
}
}
}
So basically, how do I get the view that I'm unwinding to to show up as the animation is taking place?
For completeness sake, here's the forward segue code:
class ToScheduleFocusSegue: UIStoryboardSegue {
override func perform() {
let fromView = self.source.view!
let toView = self.destination.view!
let window = UIApplication.shared.keyWindow!
let box = UIScreen.main.bounds
let schedulesList = self.source as! SchedulesListController
let cell = schedulesList.tableView.cellForRow(at: schedulesList.tableView.indexPathForSelectedRow!)!
toView.frame = cell.convert(cell.bounds, to: window).insetBy(dx: 0, dy: 0)
window.insertSubview(toView, aboveSubview: fromView)
UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
toView.frame = box
}) { (finished) in
self.source.present(self.destination, animated: false, completion: nil)
}
}
}
(This is in XCode8, targeted at iOS10 using Swift3)