有人知道iPhone上是否可以用UIPopoverPresentationController来展示Popover吗?想知道苹果是否在iOS 8上添加了这一功能,以try 为iPad和iPhone创建更统一的演示控制器.

不确定是否可以问/答Beta版的问题.那样的话,我就把它拿走.

推荐答案

您可以使用

UIPresentationController使用此方法要求使用新的演示样式,在您的情况下,只需返回UIModalPresentationNoneUIPopoverPresentationController就会呈现为popover,而不是全屏.

下面是一个在故事板中使用segue设置的Popor的例子,从UIBarButtonItem到"present modally"a UIViewController

class SomeViewController: UIViewController, UIPopoverPresentationControllerDelegate {

    // override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { // swift < 3.0
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "PopoverSegue" {
            if let controller = segue.destinationViewController as? UIViewController {
                controller.popoverPresentationController.delegate = self
                controller.preferredContentSize = CGSize(width: 320, height: 186)                
            }
        }
    }

    // MARK: UIPopoverPresentationControllerDelegate

    //func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle { // swift < 3.0
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        // Return no adaptive presentation style, use default presentation behaviour
        return .None
    }
}

这个把戏在WWDC 2014 session 214 "View Controller Advancement in iOS8"(36:30)中被提到

Objective-c相关问答推荐

OCUnit 的单元测试示例

将 NSArray 保存到 NSUserDefaults 并在 NSMutableArray 中获取它

核心数据独特属性

Xcode 中架构的重复符号

Asihttprequest 61 错误

使用 arc4random() 时如何 Select 值的范围

UICollectionView 标头未显示

如何在 Objective-C 中创建静态方法?

以流畅的动画显示/隐藏导航栏

如何在 UIAlertController 中添加 textField?

主队列上的 performSelectorOnMainThread: 和 dispatch_async() 有什么区别?

如何修复UIPopoverController 已弃用警告?

发送通知到山狮通知中心

当 UIView 框架更改时,视图内的 AVPlayer 层不会调整大小

iOS 10 中的错误:无法从 https://mesu.apple.com/assets/ 复制assets资源信息以获取assets资源类型

Apple 说 NSManagedObjectContext 归创建它的线程或队列所有时是什么意思?

UITableView,我如何知道 cellForRowAtIndexPath 期间的哪个部分?

@package 指令在 Objective-C 中的作用是什么?

如何使用图像和标签制作自定义 UIBarButtonItem?

如何将按钮放在不会在 iOS 中随表格滚动的 UITableView 上