按TabBar后弹出项目
问题描述:
我有一个tabbar
5项。 如果用户按下第三个对象,我试图让弹出窗口出现。该弹出窗口将覆盖当前屏幕,不会将它们移动到另一个屏幕。然后,一旦用户按下其中一个弹出选项,它将把它们移动到下一个屏幕。或者他们可以在弹出窗口外面按下,他们会关闭。按TabBar后弹出项目
我不确定要这样做。我在下面附加了一张图片,告诉你我想得到什么(弹出窗口中有红框)。 如何实现这一点?
///编辑/// 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)
}
唐忘了准备赛段。
如果这是为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)
}
做出第一现有解决方案进行调查。 我推荐这个网站https://www.cocoacontrols.com/search?q=tabbar 然后,请问具体问题 –