Getting started with 3D Touch

F9feb45c0a049cccc3e2563f1fe2f869?s=47 sonson
September 27, 2016

Getting started with 3D Touch

How to implement "touch and peek" function in iOS9.

F9feb45c0a049cccc3e2563f1fe2f869?s=128

sonson

September 27, 2016
Tweet

Transcript

  1. ˜ZPVSOBNF"MMSJHIUTSFTFSWFE3FEJTUSJCVUJPOPSQVCMJDEJTQMBZOPUQFSNJUUFEXJUIPVUXSJUUFOQFSNJTTJPOGSPNZPVSOBNF *OUSPEVDFUPVDIBOEQFFL 1SPHSBNNJOH ू·ΕSwift޷͖ʂSwiftѪ޷ձ vol11 :VJDIJ:PTIJEB 3FTFBSDIFS %&/40*5-BCPSBUPSZ *OD (FUUJOHTUBSUFEXJUI%UPVDI

  2. 4FMGJOUSPEVDUJPO sonson • sonson_twit@Twitter • sonsongithub@github Portfolio • 2tch(̎ͪΌΜͶΔϒϥ΢β)ͳͲͳͲ ຊۀ

    • ΫϧϚۀք • ը૾ೝࣝͱ͔ɼUIͱ͔৭ʑ΍͓ͬͯΓ·͢ ιʔεΛެ։ͯ͠Δ΋ͷ΋͋Γ·͢ IUUQHJUIVCDPNTPOTPOHJUIVC
  3. SFEEJGU 0QFOTPVSDFQSPKFDU 1ԯਓҎ্ͷΞϝϦΧͷSNS API͋Γ Objective-CͷAPI Wrapper͸͋Γ • OAuth2ʹରԠͯ͠ͳ͍ • Swift͡Όͳ͍

    Α͠ɼ͍ͬͪΐɼझຯʴษڧ͕ͯΒ࡞Δ͔ʂ MIT License
  4. 4XJGU GSPNUP ݁࿦ • beta1͔Βॱʹશ෦ରԠͨ͠ɾɾɾͳͷͰۤ࿑͕ബΕ͍ͯΔͱ͍͏͔ҧ͍͕Θ͔Βͳ͍ ۤ࿑ͨ͠ͱ͜Ζ • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε

    • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε • ҙຯෆ໌ͳ࢓༷มߋʢม਺ͷܕͱ͔ʣ
  5. 5PVDIBOEQFFL *OUSPEVDF%UPVDI ༻ҙ • registerForPreviewing(with:sourceView:) • unregisterForPreviewing(withContext:) σϦήʔτ - UIViewControllerPreviewingDelegate

    • previewingContext(_:viewControllerForLocation:) • previewingContext(_:commit:)
  6. %UPVDI 1. registerForPreviewingͰ४උ͢Δ 2. Ϣʔβ͕ڧ͘ԡ͢ 3. previewingContext(_:viewControllerForLocation:)͕ݺ͹ΕΔ 4. ԡ͞ΕͨྖҬΛઃఆ͢Δ 5.

    ͜͜Ͱview controllerΛ࡞Γɼฦ͢ 6. ࠷ޙ·Ͱڧ͘ԡ͠ࠐΉ 7. previewingContext(_:commit:)͕ݺ͹ΕΔ 8. ͜͜Ͱ͖ͬ͞࡞ͬͨview controllerΛͲ͏͢Δ͔ܾΊΔ
  7. QSFWJFXJOH$POUFYU @WJFX$POUSPMMFS'PS-PDBUJPO 1SFQBSFBWJFXDPOUSPMMFSGPSQFFLJOH ϝΠϯʹ΍Δ͜ͱ • view controllerΛ࡞Δ • ԡ͞Εͨ৔ॴͷ৘ใΛ൑ఆ͢Δ •

    ৔ॴΛcontextʹೖྗ͢Δ • view controllerͷαΠζΛܾఆ͢Δ
  8. QSFWJFXJOH$POUFYU @WJFX$POUSPMMFS'PS-PDBUJPO $SFBUFWJFXDPOUSPMMFSBOEGFUDIDPOUFOUT func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint)

    -> UIViewController? { // Create new view controller for peeking let controller = WebViewController(nibName: nil, bundle: nil) let locationInTextView = self.view.convert(location, to: textView) // get contents controller.url = getUrl(at: locationInTextView) return controller }
  9. QSFWJFXJOH$POUFYU @DPNNJU )PXJTUIFWJFXDPOUSPMMFSTIPXO ϝΠϯʹ΍Δ͜ͱ • ࠓද͍ࣔͯ͠Δview controllerΛͲ͏͢Δ͔ܾΊΔ UIViewControllerͷ͓࡞๏Ͱ΍Γ·͠ΐ͏ • modalʁ

    • pushʁ • ಠࣗʁʢ͓͢͢Ί͠ͳ͍ʣ
  10. QSFWJFXJOH$POUFYU @DPNNJU 1VTI1SFTFOUWJFXDPOUSPMMFS func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController)

    { // Modal let nav = UINavigationController(rootViewController: viewControllerToCommit) self.present(nav, animated: true, completion: nil) // Push navigationController?.pushViewController(viewControllerToCommit, animated: false) }
  11. .FOV

  12. )PXUPQSFQBSFNFOVJUFNT override var previewActionItems : [UIPreviewActionItem] { get { let

    action1 = UIPreviewAction(title: “action1”, style: .default) { previewAction, viewController in print(title) } let action2 = UIPreviewAction(title: “delete”, style: .destructive) { previewAction, viewController in print(title) } return [action1, action2] } }
  13. ۤ࿑͢Δͱ͜Ζʁ ৔ॴͷ͋Δίϯςϯπͷऔಘ • CGRect • func contains(_ point: CGPoint) ->

    Bool ͋ΔViewͷCGRect΍CGPointΛଞͷView͔Βݟͨͱ͖ɾɾɾɾ • UICoordinateSpaceϓτϩίϧΛ࢖͏ • func convert(CGPoint, to: UICoordinateSpace) • func convert(CGPoint, from: UICoordinateSpace) • func convert(CGRect, to: UICoordinateSpace) • func convert(CGRect, from: UICoordinateSpace)
  14. αϯϓϧ ιʔείʔυ • https://github.com/sonsongithub/UZTextView/tree/develop • Sample3DTouch project WWDC2016 • https://developer.apple.com/videos/play/wwdc2016/228/

  15. ·ͱΊ Swift3 • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε • SwiftͰ࡞ΒΕͨ֎෦ϥΠϒϥϦͷϝϯςφϯε

    3D touch - Touch & Peek • ׂͱ؆୯ • ରԠ͢ΔσϦήʔτ͸؆୯ • λονͨ͠৔ॴʹରԠ͢Δ৘ใΛ൑ఆ͢Δͷ͕େม