使用以编程方式创建的UIPopoverPresentationController强制iPhone上的popover [英] Force popover on iPhone with programmatically created UIPopoverPresentationController

查看:109
本文介绍了使用以编程方式创建的UIPopoverPresentationController强制iPhone上的popover的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个新的弹出视图,因为在编译期间,Interface Builder中的锚点不可见。

I need to create a new popover view as the anchor is not visible in Interface Builder during compile time.

根据这篇文章,实施委托方法将强制在iPhone上使用Popover。 (由于我不明白的原因)

According to this post, implementing the delegate method will force Popover on iPhone. (for reasons I don't understand)

在帖子中显示的segue上效果很好。但我不能让这种方式以非分段的方式发挥作用。 (Popover确实出现在iPad上)

It works great when on a segue as shown in the post. But I cannot get this to work in a non-segue way. (Popover does show up on iPad)

请帮助!

代码如下:

func showOptions() {
    let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PasteOption") as NewPasteOptionViewController
    contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
    contentView.preferredContentSize = CGSizeMake(200.0, 200.0)
    presentViewController(contentView, animated: true, completion: nil)
    var _popoverPresentationController = contentView.popoverPresentationController!
    _popoverPresentationController.delegate = self
    _popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.Any
    _popoverPresentationController.sourceView = view
    _popoverPresentationController.sourceRect = self.navigationItem.titleView!.frame
}
// this function below is never called.
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

附加说明:

呈现视图控制器在另一个视图中显示为模态表单,并封装在导航控制器中。
呈现的视图控制器是一个自定义的表视图控制器。

The presenting view controller is presented as a modal form sheet in another view, and encapsulated in a navigation controller. The presented view controller is a custom table view controller.

推荐答案

似乎正在移动 presentViewController(contentView,animated:true,completion:nil)
到函数末尾将解决问题。

It seems moving the line presentViewController(contentView, animated: true, completion: nil) to the end of the function would fix the issue.

这篇关于使用以编程方式创建的UIPopoverPresentationController强制iPhone上的popover的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆