iOS Gesture Recognizers CocoaConf Boston October 2013 Jonathan - - PowerPoint PPT Presentation

ios gesture recognizers
SMART_READER_LITE
LIVE PREVIEW

iOS Gesture Recognizers CocoaConf Boston October 2013 Jonathan - - PowerPoint PPT Presentation

iOS Gesture Recognizers CocoaConf Boston October 2013 Jonathan Penn @jonathanpenn Slides n Sample Code rubbercitywizards.com/stu ff Ti e problem... - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -


slide-1
SLIDE 1

iOS Gesture Recognizers

CocoaConf Boston • October 2013 Jonathan Penn

slide-2
SLIDE 2

@jonathanpenn

slide-3
SLIDE 3

rubbercitywizards.com/stuff

Slides n’ Sample Code

slide-4
SLIDE 4

Tie problem...

slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
  • (void)touchesBegan:(NSSet *)touches

withEvent:(UIEvent *)event

  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event

  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event

slide-10
SLIDE 10
  • (void)touchesBegan:(NSSet *)touches

withEvent:(UIEvent *)event { remember when, where for the touches }

slide-11
SLIDE 11
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-12
SLIDE 12
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-13
SLIDE 13
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-14
SLIDE 14
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-15
SLIDE 15
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-16
SLIDE 16
  • (void)touchesMoved:(NSSet *)touches

withEvent:(UIEvent *)event { if one finger: is user panning? adjust offset if two fingers: am I rotating? what angle? am I pinching? what scale? }

slide-17
SLIDE 17
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-18
SLIDE 18
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-19
SLIDE 19
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-20
SLIDE 20
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-21
SLIDE 21
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-22
SLIDE 22
  • (void)touchesEnded:(NSSet *)touches

withEvent:(UIEvent *)event { did we already pan? did we already rotate? did we already pinch? did we move to far for a tap? did we wait to long for a tap? if not: then TAP! }

slide-23
SLIDE 23

Phew!

slide-24
SLIDE 24

But wait, there’s more...

slide-25
SLIDE 25
slide-26
SLIDE 26

What we want...

slide-27
SLIDE 27
  • (void)panned:(id)coordinates

{ // ... }

  • (void)tapped:(id)coordinates

{ // ... }

  • (void)doubleTapped:(id)coordinates

{ // ... }

slide-28
SLIDE 28
slide-29
SLIDE 29

UIView

  • (void)tapped:

target/action

slide-30
SLIDE 30

How do they work?

slide-31
SLIDE 31

possible recognized failed

slide-32
SLIDE 32

possible recognized failed

slide-33
SLIDE 33

possible began changed ended cancelled

slide-34
SLIDE 34
  • (void)panned:(id)recognizer

{ // ... }

  • (void)tapped:(id)recognizer

{ // ... }

  • (void)doubleTapped:(id)recognizer

{ // ... }

slide-35
SLIDE 35

A long press by any other name takes just as long.

slide-36
SLIDE 36

By our powers combined....

slide-37
SLIDE 37

target/action target/action

UIViewController

delegate

<UIGestureRecognizerDelegate>

  • (BOOL)gestureRecognizer:...

shouldRecognizeSimultaneouslyWithGestureRecognizer:...

slide-38
SLIDE 38
  • (void)pinched:(id)recognizer

{ // ... }

  • (void)rotated:(id)recognizer

{ // ... }

slide-39
SLIDE 39
  • Reduce. Reuse. Recognize.
slide-40
SLIDE 40

To the Demo!

slide-41
SLIDE 41

Walkthrough Example

github.com/jonathanpenn/GestureExample

Mark’s Gesture Lab

github.com/markd2/GestureLab

slide-42
SLIDE 42

jonathan@rubbercitywizards.com

@jonathanpenn

for more info… rubbercitywizards.com/stuff