5

I have list of some content items it table view, and controller for options for each item. I present this options controller on 3D touch or long tap for old devices. I've implemented it in very basic way:

extension ViewController {
    func checkForForceTouch() {
        if #available(iOS 9.0, *) {
            if traitCollection.forceTouchCapability == .available {
                registerForPreviewing(with: self, sourceView: tableView)
            } else {
                addLongPressRecognizer()
            }
        } else {
            addLongPressRecognizer()
        }
    }

...
}

@available(iOS 9.0, *)
extension ViewController: UIViewControllerPreviewingDelegate {
    public func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
        if let indexPath = tableView.indexPathForRow(at: location) {
            let cell = tableView.cellForRow(at: indexPath)!
            previewingContext.sourceRect = cell.frame

            return self.optionsController(for: indexPath)
        } else {
            return nil
        }
    }

    public func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
        viewControllerToCommit.modalPresentationStyle = .overFullScreen
        present(viewControllerToCommit, animated: true, completion: nil)
    }
}

Everything works fine except one thing: in case of 3d touch options controller displays in peek view. I want to present it immediately, like Apple Music app. Is there way to do it?

frozen_lion
  • 648
  • 5
  • 18

0 Answers0