在Swift 5中关闭第一个popver并显示第二个popver的方法是通过使用popoverPresentationController来管理popover的显示和关闭。
首先,要关闭第一个popover,可以使用dismiss方法来关闭当前的popover。例如:
yourFirstPopover.dismiss(animated: true)
接下来,要显示第二个popover,需要创建第二个popover视图控制器,并设置其popoverPresentationController的相关属性,然后使用present方法来显示第二个popover。例如:
let yourSecondPopover = YourSecondPopoverViewController()
yourSecondPopover.modalPresentationStyle = .popover
// 设置第二个popover的位置和大小
yourSecondPopover.popoverPresentationController?.sourceView = yourSourceView
yourSecondPopover.popoverPresentationController?.sourceRect = yourSourceRect
// 设置第二个popover的箭头方向
yourSecondPopover.popoverPresentationController?.permittedArrowDirections = .any
// 设置第二个popover的代理
yourSecondPopover.popoverPresentationController?.delegate = self
// 显示第二个popover
present(yourSecondPopover, animated: true)
注意,你需要替换"YourSecondPopoverViewController"为你自己的第二个popover的视图控制器类名。此外,你还需要设置第二个popover的位置和大小,箭头方向等属性。
同时,你也可以通过实现popoverPresentationController的代理方法来对第二个popover进行一些自定义设置。例如:
extension YourViewController: UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
// 返回.none来保持popover的显示
return .none
}
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
// 返回true来允许点击popover外部区域来关闭popover
return true
}
}
这样,在Swift 5中你就可以关闭第一个popover并显示第二个popover了。
关于Swift 5中的popover功能,腾讯云没有特定的产品或文档提供相关信息。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云