Home / Apple iOS Development / How To Detect Shake Motion Gesture On you iPhone or iPad

How To Detect Shake Motion Gesture On you iPhone or iPad

Today we are going just to detect Shake Motion gesture on iPhone or iPad.
We are going to create a new Universal application. Just create a new project, select single view and select “Universal” on devices option

Now you have a delegate and one “ViewController”.
Open the .xib file and place a UILabel of create a new UILabel programatically in your “viewDidLoad” method. Once we placed a UILabel the you may write some text init like “No Shake”

Now we have to write down some delegate methods of “Shake Gesture”.

1
2
3
4
5
6
7
8
9
10
11
12
13
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
// you can do any thing at this stage what ever you want. Change the song in playlist, show photo, change photo or whatever you want to do
    titleLabel.text = @"Shake Started";
}
 
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{
	titleLabel.text = @"Shake Cancelled";
}
 
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
// you can do any thing at this stage what ever you want. Change the song in playlist, show photo, change photo or whatever you want to do
	titleLabel.text = @"Shake Ended";
}

That’s all now how you are going to use this thing, this is totally up to you. You may download the example project on this link ShakeGestureExample
Happy Coding and Mind Your Code :)

About Sallah Ud Din Sarwar

I am a multi skilled Software Engineer with over 4 year’s industry experience in designing and developing Object oriented solutions in Multi layered & N-Tired. I have substantial success to my credit. I have consistently handled complex problems to the satisfaction of my clients by working in stressful situations. I enjoy learning and applying new technologies in a dynamic and forward thinking professional environment.

Check Also

Find Control in .NET

It is a way of handling Nested control (NET controls on NET Container Controls) because ...

Leave a Reply

Your email address will not be published. Required fields are marked *