In this recipe, we will learn how to intercept and respond to shake gestures.
Perform the following steps:
Add a label to the view of the controller.
Enter the following code in the
MotionEventsAppViewController
class:public override bool CanBecomeFirstResponder { get { return true; } } public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); this.BecomeFirstResponder(); } public override void MotionBegan (UIEventSubtype motion, UIEvent evt) { base.MotionBegan (motion, evt); this.lblOutput.Text = "Motion started!"; } public override void MotionEnded (UIEventSubtype motion, UIEvent evt) { base.MotionEnded (motion, evt); this.lblOutput.Text = "Motion ended!"; } public override void MotionCancelled (UIEventSubtype motion, UIEvent evt) { base.MotionCancelled (motion, evt); this.lblOutput.Text = "Motion cancelled!"; }
Compile...