gpt4 book ai didi

swift - 按 T​​abBar 项目后弹出

转载 作者:行者123 更新时间:2023-11-30 12:13:40 26 4
gpt4 key购买 nike

我有一个包含 5 个项目的标签栏如果用户按下第三个对象,我试图弹出一个弹出窗口。此弹出窗口将覆盖他们当前的屏幕,而不是将其移动到另一个屏幕。然后,一旦用户按下其中一个弹出选项,它会将他们移动到下一个屏幕。或者他们可以按弹出窗口的外部,它们就会关闭。

我不确定是否要这样做。我在下面附上了一张图片,以便您了解我想要得到的内容(弹出窗口周围有红色框)。 我该如何实现这个? enter image description here

///编辑///函数 TabBar shouldSelect 方法似乎是我应该使用的东西,但是当我尝试使用简单的打印语句来实现它时,按下它时不起作用。

最佳答案

更好的方法是使用操作表而不是带有两个按钮的弹出框。

从选项卡栏项目 3 到 ViewController 创建一个导出,确保将连接设置为操作,为函数命名,在本例中我将其称为“presentCameraAndPhotos”

@IBAction func presentCameraAndPhotos(_ sender: Any) {
var alert = UIAlertController(title: "Foo", message: "Bar", preferredStyle: .actionSheet)

alert.addAction(UIAlertAction(title: "Camera", style: .default) { _ in
//Do whatever it is you want to do when camera is selected
self.performSegue(withIdentifier: "CameraVCSegueID", sender: self)
})

alert.addAction(UIAlertAction(title: "Photos", style: .default) { _ in
//Do whatever it is you want to do when photos is selected
self.performSegue(withIdentifier: "PhotoVCSegueID", sender: self)
})

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

present(alert, animated: true, completion: nil)
}

不要忘记准备segues。

如果这是针对 iPad 的,请在 VC 中为选项卡栏 3 项目设置一个 socket ,并使用类似这样的内容:

@IBAction func presentCameraAndPhotos(_ sender: Any) {
var alert = UIAlertController(title: "Foo", message: "Bar", preferredStyle: .actionSheet)

alert.addAction(UIAlertAction(title: "Camera", style: .default) { _ in
//Do whatever it is you want to do when camera is selected
self.performSegue(withIdentifier: "CameraVCSegueID", sender: self)
})

alert.addAction(UIAlertAction(title: "Photos", style: .default) { _ in
//Do whatever it is you want to do when photos is selected
self.performSegue(withIdentifier: "PhotoVCSegueID", sender: self)
})

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

alert.modalPresentationStyle = .Popover
let popoverPresentation = alert.popoverPresentationController
popoverPresentation.barButtonItem = //Whatever the outlet name of your tab bar 3 is
present(alert, animated: true, completion: nil)
}

关于swift - 按 T​​abBar 项目后弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45702582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com