Skip to content

Instantly share code, notes, and snippets.

@hsylife
Last active October 12, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsylife/6ac6cb22caa82f9bc2eccaed60e573fe to your computer and use it in GitHub Desktop.
Save hsylife/6ac6cb22caa82f9bc2eccaed60e573fe to your computer and use it in GitHub Desktop.
Popoverの2つの実装方法を比較する ref: http://qiita.com/hsylife/items/9df3dee1fc70b244da8c
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBAction func tapModalPresentationStyle(_ sender: UIButton) {
//Prepare the instance of ContentViewController which is the content of popover.
let contentVC = ContentViewController()
//define use of popover
contentVC.modalPresentationStyle = .popover
//set size
contentVC.preferredContentSize = CGSize(width: 300, height: 300)
//set origin
contentVC.popoverPresentationController?.sourceView = view
contentVC.popoverPresentationController?.sourceRect = sender.frame
//set arrow direction
contentVC.popoverPresentationController?.permittedArrowDirections = .any
//set delegate
contentVC.popoverPresentationController?.delegate = self
//present
present(contentVC, animated: true, completion: nil)
}
/// Popover appears on iPhone
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment