Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting started with 3D Touch

sonson
September 27, 2016

Getting started with 3D Touch

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

sonson

September 27, 2016
Tweet

More Decks by sonson

Other Decks in Programming

Transcript

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

    • ΫϧϚۀք • ը૾ೝࣝͱ͔ɼUIͱ͔৭ʑ΍͓ͬͯΓ·͢ ιʔεΛެ։ͯ͠Δ΋ͷ΋͋Γ·͢ IUUQHJUIVCDPNTPOTPOHJUIVC
  2. %UPVDI 1. registerForPreviewingͰ४උ͢Δ 2. Ϣʔβ͕ڧ͘ԡ͢ 3. previewingContext(_:viewControllerForLocation:)͕ݺ͹ΕΔ 4. ԡ͞ΕͨྖҬΛઃఆ͢Δ 5.

    ͜͜Ͱview controllerΛ࡞Γɼฦ͢ 6. ࠷ޙ·Ͱڧ͘ԡ͠ࠐΉ 7. previewingContext(_:commit:)͕ݺ͹ΕΔ 8. ͜͜Ͱ͖ͬ͞࡞ͬͨview controllerΛͲ͏͢Δ͔ܾΊΔ
  3. 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 }
  4. 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) }
  5. )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] } }
  6. ۤ࿑͢Δͱ͜Ζʁ ৔ॴͷ͋Δίϯςϯπͷऔಘ • 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)