【问题标题】:Segue to popover for iPhone not working in iOS 10?Segue to popover for iPhone 在 iOS 10 中不起作用?
【发布时间】:2016-08-04 00:39:58
【问题描述】:

我想继续使用 iOS 10 中的弹出框,这段代码过去在 iPhone 上可以正常工作,但现在不行(它显示全屏),我做错了什么? segue 设置为“Present As Popover”。

 override func prepare(for segue:UIStoryboardSegue, sender:AnyObject!) {  
    if segue.identifier == "about" {  
        let aboutController = segue.destination as! AboutController  
        aboutController.preferredContentSize = CGSize(width:300, height:440)  

        let popoverController = aboutController.popoverPresentationController  

        if popoverController != nil {  
            popoverController!.delegate = self  
            popoverController!.backgroundColor = UIColor.black  
        }  
    }  
}  

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

【问题讨论】:

    标签: ios iphone ios10


    【解决方案1】:

    许多函数已在 Swift 3 中重命名,包括 adaptivePresentationStyleForPresentationController - 现在是 adaptivePresentationStyle(for:)

    将您的代码更改为

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

    由于您的函数名称不匹配,因此没有被调用,并且因为它是协议中的可选函数,所以您没有收到警告。

    【讨论】:

    • 干杯 - 可选协议方法有时会导致问题的原因之一 :)
    • 这在 iOS 11 中停止工作了吗?我只能让弹出框在 iPhone 上模态显示
    【解决方案2】:

    Popover 是 iPad 独有的功能。 UIKit 足够聪明,可以判断它应该在 iPhone/iPod 上以模态方式呈现它。

    【讨论】:

    • 这是默认行为,但您可以像 OP 所做的那样通过 adaptivePresentationStyleForPresentationController 更改它。他们的问题似乎是“为什么这在 iOS 10 中不能像在早期版本的 iOS 中那样工作,我该如何解决?”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多