2017-08-15 103 views
-1

我有一个tabbar 5项。 如果用户按下第三个对象,我试图让弹出窗口出现。该弹出窗口将覆盖当前屏幕,不会将它们移动到另一个屏幕。然后,一旦用户按下其中一个弹出选项,它将把它们移动到下一个屏幕。或者他们可以在弹出窗口外面按下,他们会关闭。按TabBar后弹出项目

我不确定要这样做。我在下面附加了一张图片,告诉你我想得到什么(弹出窗口中有红框)。 如何实现这一点?enter image description here

///编辑/// TabBar shouldSelect方法的功能看起来像我应该使用的东西,但是当我尝试用一​​个简单的打印语句实现它时,它被按下不起作用。

+0

做出第一现有解决方案进行调查。 我推荐这个网站https://www.cocoacontrols.com/search?q=tabbar 然后,请问具体问题 –

回答

0

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

建立从标签栏项目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) 
} 
+0

有没有办法让我想要的风格(图片中)? – fphelp

+0

我试着实现你的代码,但是我可以使用tabbar项目的连接类型是Outlet或Outlet Connection。它不允许我将Action作为选项 – fphelp

+0

它必须是条形按钮项目,您可能必须从文档大纲中拖动它以进行连接。 –