Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
An introduction to 3D Touch for Swift developers
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
simon gladman
October 19, 2015
Programming
570
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
An introduction to 3D Touch for Swift developers
My Swift London talk of October 19, 2015 discussing 3D Touch for Swift
simon gladman
October 19, 2015
More Decks by simon gladman
See All by simon gladman
Image Processing for iOS
flexmonkey
0
1.4k
Introducing Image Processing in Metal
flexmonkey
0
500
iOS GPU Programming with Swift & Metal
flexmonkey
2
510
Creating Apps Without Interface Builder
flexmonkey
0
480
iOS GPU Programming with Swift & Metal
flexmonkey
4
36k
Other Decks in Programming
See All in Programming
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
RTSPクライアントを自作してみた話
simotin13
0
610
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
200
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
700
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
JavaDoc 再入門
nagise
1
350
スマートグラスで並列バイブコーディング
hyshu
0
140
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
340
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.2k
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
350
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
280
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
240
Featured
See All Featured
How to Ace a Technical Interview
jacobian
281
24k
Mobile First: as difficult as doing things right
swwweet
225
10k
A Soul's Torment
seathinner
6
2.9k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
The Limits of Empathy - UXLibs8
cassininazir
1
360
How to build a perfect <img>
jonoalderson
1
5.7k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
Believing is Seeing
oripsolob
1
150
Between Models and Reality
mayunak
4
340
How to train your dragon (web standard)
notwaldorf
97
6.7k
New Earth Scene 8
popppiees
3
2.3k
Transcript
3D TOUCH An introduction to 3D Touch for Swift developers
Simon Gladman for Swift London / October 2015
HELLO FLEX MONKEY • Blog: flexmonkey.blogspot.co.uk • GitHub: github.com/FlexMonkey •
Twitter: @FlexMonkey
3D TOUCH FOR USERS
3D TOUCH FOR USERS • Peek
3D TOUCH FOR USERS • Peek • Preview Actions
3D TOUCH FOR USERS • Peek • Preview Actions •
Pop
3D TOUCH FOR USERS • Peek • Preview Actions •
Pop • Quick Actions
3D TOUCH FOR USERS • Peek • Preview Actions •
Pop • Quick Actions • Pressure Sensitivity
3D TOUCH FOR DEVS • Simple API • Check device
supports 3D Touch traitCollection.forceTouchCapability == UIForceTouchCapability.Available
• Simple API • Getting force value override func touchesBegan(touches:
Set<UITouch>, withEvent event: UIEvent?) { guard let touch = touches.first else { return } let normalisedForce = touch.force / touch.maximumPossibleForce print(normalisedForce) }
• Simple API • Implementing peek and pop registerForPreviewingWithDelegate(delegate, sourceView:
sourceView) • sourceView reacts to deep press • delegate must implement UIViewControllerPreviewingDelegate
• Peeking & Popping with Previewing Delegate • Protocol contains
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
• Peeking & Popping with Previewing Delegate • Protocol contains
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController)
3D TOUCH: PEEKING • Peeking - a deep press func
previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
• Peeking func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
{ let peek = PeekViewController(hsl: hsl, delegate: previewingContext.delegate) return peek }
• Peeking let hsl: HSL unowned let delegate: UIViewControllerPreviewingDelegate required
init(hsl: HSL, delegate: UIViewControllerPreviewingDelegate) { self.hsl = hsl self.delegate = delegate super.init(nibName: nil, bundle: nil) let color = UIColor(hue: hsl.hue, saturation: hsl.saturation, brightness: hsl.lightness, alpha: 1) label.text = "Your color: \(color.getHex())" label.textAlignment = NSTextAlignment.Center smallSwatch.backgroundColor = color }
None
3D TOUCH: PREVIEW ACTIONS • Preview Actions • The previewing
delegate simply needs to implement previewActions()
• Preview Actions enum ColorPresets: String { case Red, Green,
Blue } var previewActions: [UIPreviewActionItem] { return [ColorPresets.Red, ColorPresets.Green, ColorPresets.Blue].map { UIPreviewAction(title: $0.rawValue, style: UIPreviewActionStyle.Default, handler: { (previewAction, viewController) in (viewController as? PeekViewController)?.updateColor(previewAction) }) } }
• Preview Actions func updateColor(previewAction: UIPreviewActionItem) { guard let delegate
= delegate as? ChromaTouchViewController, preset = ColorPresets(rawValue: previewAction.title) else { return } let hue: CGFloat switch preset { case .Blue: hue = 0.667 case .Green: hue = 0.333 case .Red: hue = 0 } delegate.hsl = HSL(hue: hue, saturation: 1, lightness: 1) }
None
3D TOUCH: POPPING • Popping - a deeper press func
previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController)
• Popping func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) { swatch.userInteractionEnabled
= false hslSlidersStackView.hidden = true }
None
3D TOUCH: PRESSURE SENSITIVITY • Touch gestures have ‘x’ and
‘y’ coordinates • Now have a ‘z’ coordinate corresponding to the pressure of the touch
• Override touchesMoved(): override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)
{ guard let touch = touches.first else { return } let touchLocation = touch.locationInView(self) let force = touch.force let maximumPossibleForce = touch.maximumPossibleForce let normalisedXPosition = touchLocation.x / frame.width let normalisedYPosition = touchLocation.y / frame.height let normalisedZPosition = force / maximumPossibleForce hsl = HSL(hue: normalisedXPosition, saturation: normalisedYPosition, lightness: normalisedZPosition) sendActionsForControlEvents(.ValueChanged) }
None
GESTURE RECOGNISERS • As an alternative to overriding a control’s
touch handling methods • By extending UIGestureRecognizer let deepPressGestureRecognizer = DeepPressGestureRecognizer(target: self, action: "deepPressHandler:", threshold: 0.75) button.addGestureRecognizer(deepPressGestureRecognizer)
• Handle user’s actions in gesture recogniser’s touch handlers override
func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent) { guard let view = view, touch = touches.first where touch.force != 0 && touch.maximumPossibleForce != 0 else { return } if !deepPressed && (touch.force / touch.maximumPossibleForce) >= threshold { state = UIGestureRecognizerState.Began deepPressed = true } else if deepPressed && (touch.force / touch.maximumPossibleForce) < threshold { state = UIGestureRecognizerState.Ended deepPressed = false } }
TOUCH COALESCING • touchesMoved() samples at up to 60 hertz
TOUCH COALESCING • touchesMoved() samples at up to 60 hertz
• iPhone 6s has a touch sample rate of 120 hertz
TOUCH COALESCING • touchesMoved() samples at up to 60 hertz
• iPhone 6s has a touch sample rate of 120 hertz • iPad Pro will sample touches at 240 hertz
• The missing touches can be accessed through the event’s
coalescedTouches override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesMoved(touches, withEvent: event) guard let touch = touches.first, coalescedTouches = event?.coalescedTouchesForTouch(touch) else { return } for coalescedTouch in coalescedTouches { let locationInView = coalescedTouch.locationInView(view) print(locationInView) } }
None
SOME DEMO APPS
None
None
None
None
None
http://goo.gl/rzPExI flexmonkey.blogspot.co.uk github.com/FlexMonkey