Generally I followed the instructions here: https://stackoverflow.com/a/24687152/3741933.
However, as discussed in its comments, the popover is always fullscreen regardless of preferredContentSize
or sourceRect
.
The button to present the popover:
func buttonClicked(sender: UIButton!) {
let ac = EmptyViewController() as UIViewController
ac.modalPresentationStyle = .Popover
ac.preferredContentSize = CGSizeMake(200, 200)
let popover = ac.popoverPresentationController
popover?.delegate = self
popover?.permittedArrowDirections = .Any
popover?.sourceView = self.view
popover?.sourceRect = CGRect(x: 100, y: 100, width: 100, height: 100)
presentViewController(ac, animated: true, completion: nil)
}
The UIViewController:
import UIKit
class EmptyViewController : UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.redColor()
}
}
I am wondering how to make it a real popover (not full screen size). By the way, as @EI Captain indicated, it works perfectly on iPad but always fullscreen on iPhone.