我们是否可以在iPhone设备中使用Swift创建类似UIPopOver的iPhone,其中源是UIButton。我从UIBarButtonItem创建了UIPopOver,它工作得很好,但在UIButton上就不行了。有人能尽快提出一个更好的解决方案吗?我需要在iPhone设备中工作。
发布于 2016-08-10 14:34:02
可以,但需要实现popoverPresentationController的委托
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("AnnotationInfoViewController") as! PopUpViewController
//If you want to show view from XIB file you can create viewController instance like this
//let viewController = UIViewController()
//let myView = NSBundle.mainBundle().loadNibNamed("PopUpView", owner: self, options: nil)[0] as! PopUpView
//viewController.view = myView
//Pass the information that you want to show
viewController.data = passdata
//Set the viewController for popoverPresentationController
viewController.modalPresentationStyle = .Popover
viewController.preferredContentSize = CGSize(width: viewController.view.frame.size.width, height: 80)
viewController.popoverPresentationController!.delegate = self;
viewController.popoverPresentationController!.permittedArrowDirections = [.Up , .Down]
viewController.popoverPresentationController!.sourceView = yourBtn!
viewController.popoverPresentationController!.sourceRect = yourBtn.frame
self.presentViewController(viewController, animated: true, completion: nil)现在在ViewController中实现这个popoverPresentationController方法
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None;
}https://stackoverflow.com/questions/38865758
复制相似问题