3D接触偷看 - 背景迷离颜色

时间:2017-03-03 17:07:26

标签: ios xcode uiviewcontroller 3dtouch peek

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

例如,它在iMessage中是轻微模糊,但在FaceTime应用程序中模糊不清。

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

enter image description here

这是从上下文亮度自动完成的吗?背景视图亮度?窥视上下文亮度?或者我们对此有何控制权?

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)
    }
}

1 个答案:

答案 0 :(得分:3)

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

要将偷看模糊样式从亮变为暗,您可以将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
    }
}