xcode - 检测弹出窗口关闭

标签 xcode swift uikit uipopover

我知道我可以使用 popoverPresentationControllerDidDismissPopover 但只有当用户点击弹出窗口 View 外部以关闭它时才会调用它。 当我手动关闭弹出窗口时(self.dismissViewControllerAnimated(true, completion: nil) 在弹出窗口的 ViewController 中)没有任何反应。

最佳答案

弹出窗口关闭!

有两种检测弹出窗口关闭的方法:

  1. mainViewController 中检测,它实际生成的地方,我的意思是 ParentViewController

使用parentViewController作为主生成个人

class ViewController: UIViewController, UITableViewDataSource,
UITableViewDelegate, UIPopoverPresentationControllerDelegate {

现在实现这些功能:

public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

public func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
    print("Popover dismisssed")
}
  1. 在用于处理 Storyboard 中制作的 popOverView 的 Controller 中进行检测。
func dismiss() {
    self.dismiss(animated: true, completion: nil)
    print("DISMISSS")
}
    
@IBAction func cancelClicked(_ sender: Any) {
    dismiss()
}

注意:对于 Storyboard,您可以询问更多详细信息。

关于xcode - 检测弹出窗口关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36246574/

相关文章:

objective-c - Apple 的 UIView AnimationCurve EaseInOut 的实际方程式是什么?

ios - 在 iOS 上,如果 drawRect 不使用传入的矩形,那么 [self setNeedsDisplayInRect :rect] passes in a rect? 是否重要

ios - 使用 CMake 的 Xcode 部署信息和图标

objective-c - 如何在Objective-C的宏中使用三元运算符?

iphone - 在我的步行/运行应用程序中发现错误的距离和路线

ios - 如何为 UIBarButtonItem 设置标题?

swift - 如何使用 XCTWaiter 和异常快速测试异步函数

objective-c - 如何以编程方式或通过按钮等方式触发 IBAction 方法?

swift - 如何访问从 Realm Swift 中的主键查询返回的对象的属性

ios - 布局 UITextField 无论清除按钮 X