简体   繁体   English

Popover 在 iPhone 上不起作用

[英]Popover Doesn't Work on iPhone

I implemented a Popover in my application and tested it.我在我的应用程序中实现了一个Popover并对其进行了测试。 It will work fine on iPad but when I test it on iPhone, instead of showing Popover it will show the full storyboard. Please help me.它可以在 iPad 上正常工作,但是当我在 iPhone 上测试它时,它不会显示Popover ,而是会显示完整的 storyboard。请帮助我。

Here is my code:这是我的代码:

@IBAction func MenuIsClick(sender: AnyObject) {
    var moveToNextVC:MenuViewController

    moveToNextVC = self.storyboard?.instantiateViewControllerWithIdentifier("MenuViewController") as! MenuViewController
    moveToNextVC.modalPresentationStyle = .Popover
    moveToNextVC.preferredContentSize = CGSizeMake(200, 200)

    if let popoverController = moveToNextVC.popoverPresentationController {
        popoverController.sourceView = sender as! UIView
        popoverController.sourceRect = CGRect(x: 0, y: 0, width: 85, height: 30)
        popoverController.permittedArrowDirections = .Any
        popoverController.delegate = self

    }
    presentViewController(moveToNextVC, animated: true, completion: nil)

}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle {
    return .None
}

Edit: As Popover is not work on iPhone but when a refer this EthanStrider/iOS-Projects it will work fine.编辑:由于 Popover 在 iPhone 上不起作用,但是当参考这个EthanStrider/iOS-Projects时它会正常工作。 How?如何?

UIPopoverController's are only available on iPad. UIPopoverController仅在iPad上可用。

Popover controllers are for use exclusively on iPad devices. Popover控制器专用于iPad设备。 Attempting to create one on other devices results in an exception. 尝试在其他设备上创建一个会导致异常。

Though with iOS 8+, it no longer crashes, it will be executed as full screen modal presentation.. 尽管使用iOS 8+,它不再崩溃,它将作为全屏模式演示文稿执行。

A UIPopoverController is meant for use only on iPad devices. UIPopoverController仅可用于iPad设备。 You can refer to the Apple docs to verify. 您可以参考Apple文档进行验证。

If you really want a popover on iPhone, you can use a third-party control like WYPopoverController . 如果您确实希望在iPhone上安装弹出 ,则可以使用WYPopoverController之类的第三方控件。

you can use this control else. 您可以使用其他控件。

https://github.com/50pixels/FPPopover/ https://github.com/50pixels/FPPopover/

For me the problem was the .none parameter in this delegate method.对我来说,问题是这个委托方法中的.none参数。 When I added UIModalPresentationStyle in front of it - it started to work!当我在它前面添加UIModalPresentationStyle - 它开始工作了!

// Override the iPhone behavior that presents a popover as fullscreen
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.none
}

The reason was that I had another .none case defined in an enum in my project with another underlying Int value (which is of course bad practice, so please avoid that to begin with).原因是我在项目的枚举中定义了另一个.none案例,其中包含另一个基础 Int 值(这当然是不好的做法,所以请一开始就避免这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM