shake detection in iPhone which is presented as ModalViewController from appdelegete?
-
07-03-2021 - |
質問
although this is a answered question here. the solution works fine in rootviewcontroller of the appdelegate. if same methods are written in a viewcontroller which is presented as a modalviewcontroller from the app delegate it doesn't work :(. can somebody help me out.
thanks in advance!!
解決
I got the answer after breaking head for a day!!! (maybe a piece of cake for others).
here goes the solution:
In the root view controller or view controller from where we present modal view controller we have to detect shake:
- (void) viewWillAppear:(BOOL)animated
{
[self becomeFirstResponder];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated
{
//[self resignFirstResponder];
/*dont resign first responder on view disappear */
[super viewWillDisappear:animated];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if ( event.subtype == UIEventSubtypeMotionShake )
{
// Put in code here to handle shake
}
if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
[super motionEnded:motion withEvent:event];
}
present the modal view normally... shake will be detected in modalview also... Its tested and working!! Thanks all :)
所属していません StackOverflow