2017-08-15 100 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

它必須是條形按鈕項目,您可能必須從文檔大綱中拖動它以進行連接。 –