Sha256: ed633f07de96dcec4d0fbe31ae68e41a6067effb6cfeb3fd7247db7d2d391308
Contents?: true
Size: 1.5 KB
Versions: 6
Compression:
Stored size: 1.5 KB
Contents
# Opens UIView to add methods for working with gesture recognizers. class UIView def whenTapped(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UITapGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end def whenPinched(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UIPinchGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end def whenRotated(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UIRotationGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end def whenSwiped(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UISwipeGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end def whenPanned(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UIPanGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end def whenPressed(enableInteraction=true, &proc) addGestureRecognizerHelper(proc, enableInteraction, UILongPressGestureRecognizer.alloc.initWithTarget(proc, action:'call')) end private # Adds the recognizer and keeps a strong reference to the Proc object. def addGestureRecognizerHelper(proc, enableInteraction, recognizer) setUserInteractionEnabled true if enableInteraction && !isUserInteractionEnabled self.addGestureRecognizer(recognizer) @recognizers = {} unless @recognizers @recognizers["#{proc}"] = proc end end
Version data entries
6 entries across 6 versions & 1 rubygems