Created
August 8, 2021 04:07
-
-
Save imdp6/d5b525e4031c48dd4b26dcfbf57c6a7b to your computer and use it in GitHub Desktop.
▼
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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