Search code examples
iosxcodeuiviewcontroller3dtouchpeek

3D Touch Peek - Background Blur Color


When 3D Touch Peek is invoked, the background blur that happens, I notice it varies.

For example, it's a LIGHT blur in iMessage, but DARK blur in FaceTime App.

(Although below image might not be the best example to show the contrast, you can notice it better through out iOS 10)

enter image description here

Is this done automatically from the context brightness? Background View brightness? Peek context brightness? Or do we have any control over this?


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

Solution

  • I was messing around with some properties of UIViewController trying to figure out how to do this, and it turns out that changing preferredStatusBarStyle will change the blur color.

    To change the peek blur style from light to dark, you can change preferredStatusBarStyle from .default to .lightContent

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

    This also works with a hidden status bar

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