UIPreviewInteraction: Overview

UIPreviewInteraction: Overview

Fb69c72d5af289d6674d2659246a5291?s=128

Tomohiro Nishimura

June 22, 2016
Tweet

Transcript

  1. UIPreviewInteraction : Overview 2016/06/22 ؔ੢ϞόΠϧΞϓϦݚڀձ

  2. id:Sixeight @tomohi_ro

  3. None
  4. Peek and Pop

  5. 2 ways • Storyboard Segue • UIViewControllerPreviewingDelegate

  6. Storyboard Segue

  7. Storyboard Segue override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "previewSegue" { // for preview } }
  8. UIViewControllerPreviewingDelegate class ItemListViewController: UITableViewController, UIViewControllerPreviewingDelegate { // ... }

  9. UIViewControllerPreviewingDelegate override func viewDidLoad() { super.viewDidLoad() registerForPreviewing(with: self, sourceView: tableView)

    }
  10. UIViewControllerPreviewingDelegate Peek func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) ->

    UIViewController? { guard let indexPath = tableView.indexPathForRow(at: location) else { return nil } let detailViewController = DetailViewController.instantiate() detailViewController.item = item(at: indexPath) let cellRect = tableView.rectForRow(at: indexPath) let sourceRect = previewingContext.sourceView.convert(cellRect, from: tableView) previewingContext.sourceRect = sourceRect return detailViewController }
  11. UIViewControllerPreviewingDelegate Pop func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {

    show(viewControllerToCommit, sender: self) }
  12. None
  13. None
  14. How?

  15. Custom Transitioning • UIViewControllerTransitioningDelegate • UIViewControllerAnimatedTransitioning • UIViewControllerInteractiveTransitioning • UIPresentationController

    • UIGestureRecognizer
  16. None
  17. 0.0 ʙ 1.0

  18. UIPreviewInteraction

  19. None
  20. UIPreviewInteraction class DetailViewController : UIViewController { private var moreDetailPreviewInteraction: UIPreviewinteraction!

    private var moreDetailVC = MoreDetailViewController() // ... }
  21. UIPreviewInteraction override func viewDidLoad() { super.viewDidLoad() moreDetailPreviewInteraction = UIPreviewInteraction(view: view)

    moreDetailPreviewInteraction.delegate = self }
  22. UIPreviewInteractionDelegate extension DetailViewController : UIPreviewInteractionDelegate { }

  23. UIPreviewInteractionDelegate • previewInteractionShouldBegin(_ previewInteraction: UIPreviewInteraction) -> Bool • previewInteraction(_ previewInteraction:

    UIPreviewInteraction, didUpdatePreviewTransition transitionProgress: CGFloat, ended: Bool) • previewInteraction(_ previewInteraction: UIPreviewInteraction, didUpdateCommitTransition transitionProgress: CGFloat, ended: Bool)
  24. UIPreviewInteractionDelegate • previewInteractionDidCancel(_ previewInteraction: UIPreviewInteraction)

  25. UIPreviewInteractionDelegate func previewInteractionShouldBegin(_ previewInteraction: UIPreviewInteraction) -> Bool { return presentedViewController

    != nil }
  26. UIPreviewInteractionDelegate func previewInteraction(_ previewInteraction: UIPreviewInteraction, didUpdatePreviewTransition transitionProgress: CGFloat, ended: Bool)

    { // Initialize if presentedViewController != nil { present(moreDetailVC, animated: true) } // Update progress moreDetailVC.interactiveTransitionProgress = transitionProgress // Peek has finished if ended { moreDetailVC.completeCurrentInteractiveTransition() } }
  27. UIPreviewInteractionDelegate func previewInteraction(_ previewInteraction: UIPreviewInteraction, didUpdateCommitTransition transitionProgress: CGFloat, ended: Bool)

    { // Update committing progress moreDetailVC.overInteractionProgress = transitionProgress // Pop has finished if ended { tailVC.overInteractionProgress = 0.0 } }
  28. UIPreviewInteractionDelegate func previewInteractionDidCancel(_ previewInteraction: UIPreviewInteraction) { moreDetailVC.cancelCurrentInteractiveTransition() moreDetailVC.dismiss(animated: true) }

  29. Conclusion (Japanese) • Preview ࣗମͷڍಈΛΧελϚΠζͰ͖ΔͷͰ͸ͳͯ͘ɺ3D Touch Ͱԡ͠ࠐΜͩͱ͖ͷ Preview ͷਐḿ۩߹Λऔಘग़དྷΔ •

    ࣮ࡍͷ Transition ͸͜Ε·Ͱͷํ๏Λͦͷ··࢖͑Δ • Cancel ͕औΕΔͷ͸خ͍͠ؾ͕͢Δ
  30. References • https://developer.apple.com/videos/play/wwdc2016/228/ • https://developer.apple.com/reference/uikit/ uipreviewinteraction • https://developer.apple.com/reference/uikit/ uipreviewinteractiondelegate

  31. കӍ͸δϝδϝͯ͠ݏͰ͢Ͷ