我有一个tabbar
有5个项目。 如果用户按下第三个对象,我会尝试弹出一个弹出窗口。此弹出窗口将覆盖当前屏幕,而不会将其移动到另一个屏幕。然后,一旦用户按下其中一个弹出选项,它将移动到下一个屏幕。或者他们可以在弹出窗口外按压它们将关闭。
我不确定要这样做。我已经在下面附上了一张图片,如果你想要得到的东西(弹出窗口周围有红色框)。 如何实施?
///编辑///函数TabBar shouldSelect方法似乎是我应该使用的东西,但当我尝试使用简单的print语句实现它时,如果它被按下不起作用。
答案 0 :(得分:0)
更好的方法是使用操作表而不是带有两个按钮的弹出窗口。
从标签栏项目3到ViewController创建一个插座,确保将Connection设置为Action,为该函数命名,对于此示例,我将其称为“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)
}
不要忘记准备赛段。
如果这是针对iPad的,请为VC中的标签栏3项设置一个插座,并使用类似的内容:
@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)
}