无法在横向视图中关闭 EKEventViewController

发布于 2025-01-21 00:12:15 字数 446 浏览 1 评论 0原文

当我使用 EKEventViewController 在应用程序中打开日历事件时,使用下面的代码可以在模式视图中正确显示我的事件。

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

在纵向模式下(使用 iOS 15),我可以使用向下滑动手势来关闭模式。但是,当我更改为横向时,手势不起作用,并且也没有后退或取消按钮(就像 EKEventEditViewController 那样)。我找不到视图控制器的任何属性可以让我关闭它。

因此,用户要么被卡住,要么必须将设备切换为纵向模式。我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏辞 2025-01-28 00:12:15

我希望 EKEventViewController 提供一种类似方便且直观的方法来在横向视图中将其关闭,就像在纵向视图中一样,但没有任何运气。

为了获得后退按钮,我现在将模态视图包含在其自己的导航控制器中。这会显示一个“完成”按钮(以及一个删除按钮)。这两个按钮都不会关闭视图。这可以通过在父视图控制器中实现 EKEventViewDelegate 来完成。

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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文