0

When I open a calendar event in my app using EKEventViewController using the code below it correctly displays my event in a modal view.

let eventModalVC = EKEventViewController()
eventModalVC.event = myEvent
eventModalVC.allowsEditing = true
present(eventModalVC, animated: true, completion: nil)

In portrait mode (using iOS 15) I can dismiss the modal using a swipe-down gesture. However, when I change to landscape orientation, the gesture does not work, and there is no back or cancel button either (like there is for the EKEventEditViewController). I could not find any property of the view controller that would enable me to dismiss it.

So the user is either stuck or has to turn the device into portrait mode. How can I fix this?

1 Answers1

0

I was hoping that the EKEventViewController offers a similar convenient and intuitive way to dismiss it in landscape view as it does in portrait view but have not had any luck.

To get the back button I now enclosed my modal view in its own navigation controller. That reveals a "Done" button (as well as a delete button). Neither button dismisses the view. That can be done by implementing EKEventViewDelegate in the parent view controller.

let eventModalVC = EKEventViewController()
eventModalVC.event = myEvent
eventModalVC.allowsEditing = true
let nc = UINavigationController(rootViewController: eventModalVC)
eventModalVC.delegate = self
present(nc, animated: true, completion: nil)

...

// EKEventViewDelegate
func eventViewController(_ controller: EKEventViewController, didCompleteWith action: EKEventViewAction) {
    if action == .done {
        controller.dismiss(animated: true)
    }
    // handle deletion as well if needed
}