iOS 9演示Popover全屏播放

iOS 9演示Popover全屏播放,ios,swift,swift2,ios9,Ios,Swift,Swift2,Ios9,我试图展示一个PopOver视图控制器,特别是在文本字段旁边显示一个小的过滤器屏幕。但是,它显示为全屏视图控制器。应该触发弹出按钮的按钮。你知道为什么它会像普通的ViewController一样全屏显示吗 func showFilters(){ let tableViewController = UITableViewController() tableViewController.modalPresentationStyle = UIModalPresentationStyle

我试图展示一个PopOver视图控制器,特别是在文本字段旁边显示一个小的过滤器屏幕。但是,它显示为全屏视图控制器。应该触发弹出按钮的按钮。你知道为什么它会像普通的ViewController一样全屏显示吗

func showFilters(){
    let tableViewController = UITableViewController()
    tableViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
    tableViewController.preferredContentSize = CGSizeMake(20, 20)

    presentViewController(tableViewController, animated: true, completion: nil)

    let popoverPresentationController = tableViewController.popoverPresentationController
    popoverPresentationController?.sourceView = filters_button
    popoverPresentationController?.sourceRect = CGRectMake(0, 0, filters_button.frame.size.width, filters_button.frame.size.height)
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return .None
}
注意:在我的类的顶部,我声明它符合“UIPopoverPresentationControllerDelegate”协议 鉴于PopOver要在iPhone设备上工作,需要在显示viewController之前设置PopoOverPresentationController的委托,这样委托才能调用下面的方法。所以加上

    popoverPresentationController?.delegate = self
下面

    popoverPresentationController?.sourceRect = filters_button.frame
搬家

    self.presentViewController(filtersVC, animated: true, completion: nil)
到函数的末尾

已修复: 鉴于PopOver要在iPhone设备上工作,需要在显示viewController之前设置PopoOverPresentationController的委托,这样委托才能调用下面的方法。所以加上

    popoverPresentationController?.delegate = self
下面

    popoverPresentationController?.sourceRect = filters_button.frame
搬家

    self.presentViewController(filtersVC, animated: true, completion: nil)

到函数的末尾

您应该添加以下内容

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return .none
}

您应该添加以下内容

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    return .none
}

@Lu_uu.Apple不赞成iOS 8.3中的操作表。请尝试将行更改为
popoverPresentationController?.sourceView=self.view
popoverPresentationController?.sourceRect=filters\u按钮。frame
我更改了这两行,结果相同,popOver显示在整个屏幕中…在PopoOverPresentationController行之后,将presentViewController行移动到方法的末尾是否可行?否。。。我只是想确认一下,但这并没有改变任何事情。@Lu\uApple不赞成iOS 8.3版中的操作表,或者尝试将行更改为
popoverPresentationController?.sourceView=self.view
popoverPresentationController?.sourceRect=filters\u按钮.frame
我更改了这两行,结果相同,popOver显示在整个屏幕中…在PopoOverPresentationController行之后,将presentViewController行移动到方法的末尾是否可行?否。。。我尝试了它只是为了确保它不会改变任何事情。代理调用了什么方法?@SpaceDog
adaptivePresentationStyle
仅在代理已设置时生效。代理调用了什么方法?@SpaceDog
adaptivePresentationStyle
仅在代理已设置时生效。