Estou tentado fazer um menu PopOver
semelhante o do WhatsApp
mas sem sucesso. Queria fazer um menu semelhante ao abaixo.
O único menu PopOver
que consigo fazer é com o fundo branco e ocupa a tela inteira, mesmo sendo PopOver
.
Stack Overflow em Português é um site de perguntas e respostas para programadores profissionais e entusiastas. Leva apenas um minuto para se inscrever.
Inscreva-se para participar desta comunidadeEstou tentado fazer um menu PopOver
semelhante o do WhatsApp
mas sem sucesso. Queria fazer um menu semelhante ao abaixo.
O único menu PopOver
que consigo fazer é com o fundo branco e ocupa a tela inteira, mesmo sendo PopOver
.
O que você precisa implementar na verdade se chama UIAlertController:
func displayAlertMenu() {
let alert = UIAlertController(title: "Selecione a origem", message: nil, preferredStyle: .actionSheet)
let cameraAction = UIAlertAction(title: "Tirar Foto ou Filmar Video", style: .default) {
action in
// call display camera method
}
let galleryAction = UIAlertAction(title: "Escolher Foto Existente", style: .default) {
action in
// call display gallery method
}
let cancelAction = UIAlertAction(title: "Cancelar", style: .cancel) {
action in
print("user tapped the cancel button")
}
alert.addAction(cameraAction)
alert.addAction(galleryAction)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
}
E chame o metodo quando a sua view aparecer ou ao apertar de um botão:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
displayAlertMenu()
}