I am building a map application similar to Apple Maps. Basically a half height sheet over a full screen map.
How shall I structure and detect transitions between view controllers on the sheet to update the map accordingly.
For example, let’s say I have a Welcome VC and a Nearby Bus Stops VC. When the user goes from Welcome VC to Nearby Bus Stops VC, I want to add new bus stop annotations on the map. When the user go back to the Welcome VC from the Nearby Bus Stops VC, remove the annotations.
At the moment, I have a bunch of if-else statements which are not scalable as more view controllers are added and different possible combinations of transitions between view controllers are now possible in my app.
extension MainViewController: SheetControllerDelegate {
func didChangeViewInSheet(from previousVC: UIViewController, to currentVC: UIViewController) {
print("Changing from (previousVC) to (currentVC)")
if currentVC is NearbyBusStopsVC && previousVC is WelcomeVC {
removeBusStopAnnotations()
} else if currentVC is NearbyBusStopsVC && previousVC is WelcomeVC {
addBusStopAnnotations()
//More code to run during this transition of view controllers in the sheet
}
}
}