本文介绍了适用于iPhone的UIButton的UIPopOver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用源为UIButtonSwift在iPhone设备中创建类似UIPopOver的iPad吗?我从UIBarButtonItem创建了UIPopOver,它可以正常工作,但在UIButton的情况下不起作用.任何人都可以尽快提出更好的解决方案.我需要在iPhone设备上使用它.

Can we create iPad like UIPopOver in iPhone devices using Swift where source is UIButton. I created UIPopOver from UIBarButtonItem and its working fine but It's not working in case of UIButton. Can anyone suggest a better solution asap. I need to work it in iPhone device.

推荐答案

可以,但是您需要实现popoverPresentationController

Yes you can, but you need to implement delegate of 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

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return .None;
}

这篇关于适用于iPhone的UIButton的UIPopOver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 10:14