Last active
October 12, 2016 14:30
-
-
Save hsylife/6ac6cb22caa82f9bc2eccaed60e573fe to your computer and use it in GitHub Desktop.
Popoverの2つの実装方法を比較する ref: http://qiita.com/hsylife/items/9df3dee1fc70b244da8c
This file contains 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, 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