That's my code.
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(shake) name:@"shake" object:nil];
if(event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake)
{
// SOMETHING HERE
}
NSLog(@"motion Began");
}
else
{
NSLog(@"Shake Is Over");
}
}
I want to shake/motion on my device.I used that code but it is not working..
write down below code...then check
-(BOOL) canBecomeFirstResponder {
return YES;
}
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//your stuff
}
-(void)viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
-(void)viewDidDisappear:(BOOL)animated {
[self resignFirstResponder];
}
let me know it is working or not!!!
Happy Coding!!!!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加