Custom demo spread

I am making my first custom segue animations. I want to have a list view that when I select a row, instead of sliding from the side, expands in place from the selected row. Sort of:

enter image description here

Thus, the user selects the green line, which causes the new controller to start with the green line size and expand to fill the screen. So far, this part has worked fine.

, , , , , , . , , , , , , . , , - - :

enter image description here

, , :

enter image description here

, perform, :

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)
        }
    }
}

, , , , ?

, :

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)
        }
    }
}

( XCode8, iOS10 Swift3)

+4
1

, .

, :

UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
        fromView.frame = targetFrame
    }) { (finished) in
        self.destination.dismiss(animated: false, completion: nil) // the destination is the one that presented the current view
    }
0

Source: https://habr.com/ru/post/1657001/


All Articles