Skip to content

Instantly share code, notes, and snippets.

@imdp6
Created August 8, 2021 04:07
Show Gist options
  • Select an option

  • Save imdp6/d5b525e4031c48dd4b26dcfbf57c6a7b to your computer and use it in GitHub Desktop.

Select an option

Save imdp6/d5b525e4031c48dd4b26dcfbf57c6a7b to your computer and use it in GitHub Desktop.
class ViewController: UIViewController {
@objc
func clickButton() {
//get the button frame
/* 1 */
let button = UIButton.init(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
/* 2 */
//Configure the presentation controller
let popoverContentController = BViewController()
popoverContentController.modalPresentationStyle = .popover
/* 3 */
// Present popover
if let popoverPresentationController = popoverContentController.popoverPresentationController {
popoverPresentationController.permittedArrowDirections = .up
popoverPresentationController.sourceView = self.view
popoverPresentationController.sourceRect = button.frame
popoverPresentationController.delegate = self
self.present(popoverContentController, animated: true, completion: nil)
}
}
}
extension ViewController: UIPopoverPresentationControllerDelegate {
// func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {
//
// }
//
// func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
//
// }
//
// func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
//
// }
//
// func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
// return true
// }
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
// func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
//
// }
//
// func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
// return true
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment