Ответ 1
Обновлен для Swift 3
В раскадровке добавьте контроллер просмотра, которым вы хотели бы быть popover. Установите идентификатор раскадровки "popoverId".
Также добавьте кнопку в свой основной контроллер представления и подключите IBAction к следующему коду.
import UIKit
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBAction func buttonTap(sender: UIButton) {
// get a reference to the view controller for the popover
let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popoverId")
// set the presentation style
popController.modalPresentationStyle = UIModalPresentationStyle.popover
// set up the popover presentation controller
popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
popController.popoverPresentationController?.delegate = self
popController.popoverPresentationController?.sourceView = sender // button
popController.popoverPresentationController?.sourceRect = sender.bounds
// present the popover
self.present(popController, animated: true, completion: nil)
}
// UIPopoverPresentationControllerDelegate method
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
// Force popover style
return UIModalPresentationStyle.none
}
}
Настройка sourceView
и sourceRect
- это то, что позволяет вам выбрать произвольную точку для отображения popover.
Что это. Теперь ему нужно что-то подобное, когда кнопка нажата.
Спасибо этой статье за помощью.