3D Touch Peek - 背景模糊颜色

3D Touch Peek - Background Blur Color

当调用 3D Touch Peek 时,发生的背景模糊,我注意到它有所不同。

例如,它在 iMessage 中是浅色模糊,但在 FaceTime 应用程序中是深色模糊。

(虽然下图可能不是显示对比度的最佳示例,但您可以通过 iOS 10 更好地注意到它)

这是根据上下文亮度自动完成的吗?背景查看亮度?查看上下文亮度?或者我们对此有任何控制吗?


extension ChatTableViewController: UIViewControllerPreviewingDelegate {
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
        guard let indexPath = tableView.indexPathForRow(at: location) else { return nil }

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = storyboard.instantiateViewController(withIdentifier: ChatDetailViewController.identifier)
        guard let chatDetailViewController = viewController as? ChatDetailViewController else { return nil }

        chatDetailViewController.chatItem = chatItem(at: indexPath)
        let cellRect = tableView.rectForRow(at: indexPath)
        previewingContext.sourceRect = previewingContext.sourceView.convert(cellRect, from: tableView)
        chatDetailViewController.isReplyButtonHidden = true

        return chatDetailViewController
    }

    func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
        if let chatDetailViewController = viewControllerToCommit as? ChatDetailViewController {
            chatDetailViewController.isReplyButtonHidden = false
        }
        show(viewControllerToCommit, sender: self)
    }
}

我正在研究 UIViewController 的一些属性,试图找出如何做到这一点,结果发现改变 preferredStatusBarStyle 会改变模糊颜色。

要将 peek 模糊样式从浅色更改为深色,您可以将 preferredStatusBarStyle.default 更改为 .lightContent

class MyViewController: UIViewController{
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
}

这也适用于隐藏状态栏

class MyViewController: UIViewController{
    override var prefersStatusBarHidden: Bool{
        return true
    }

    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
}