0

I have a problem in reacting to a shake event. First problem is that if I place the shake view on root then it works fine, but when i flip to other views and come back it doesn't work at all. Second problem is that if I use shake and then flip to a view which has a UITextField in it then UITextField does not respond and no keyboard appears. I can provide my code if any body wants. Needing to resolve this issue badly.

Regards.

Edit:

Following is the code of root view (where i am using shake event):

enter -(BOOL) canBecomeFirstResponder{
return YES;} 

-(void) viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];
[self becomeFirstResponder];}

-(void) viewDidDisappear:(BOOL)animated{
[self resignFirstResponder];

[super viewDidDisappear:animated];}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    if(event.subtype == UIEventSubtypeMotionShake)
    {

        iv.transform = CGAffineTransformMakeScale(1.0, 1.0);
        txtviewFortune.text = nil;

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];


        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];


        iv.transform = CGAffineTransformMakeScale(2.0, 2.0);


        [UIView commitAnimations];


    }
}
Wasim
  • 1,349
  • 12
  • 16
  • @Wasim send code by mail or post your code. – Rahul Vyas Jun 24 '11 at 11:50
  • @Wasim please post more code or send in email if you can. The code you have posted right now is seems ok. – Rahul Vyas Jun 24 '11 at 12:12
  • what else i can post ? I am just flipping using the regular flipping code and then return on this view. Thats all. – Wasim Jun 24 '11 at 12:13
  • @Wasim why did you write this code [self resignFirstResponder]; [self becomeFirstResponder]; – Rahul Vyas Jun 24 '11 at 12:14
  • 1
    @Wasim read this post it might help you http://stackoverflow.com/questions/1340492/how-to-detect-and-program-around-shakes-for-the-iphone – Rahul Vyas Jun 24 '11 at 12:16
  • I was just testing that [self resignFirstResponder] can solve my problem or not – Wasim Jun 24 '11 at 12:22
  • Thanks for posting this link, but my problem is a little different from this one. In this example he isnt using any other views, he is just trying to shake which i already accomplished. I am facing problem when I come back on my root view after flipping from another view, then my root view's shake event stopped working. – Wasim Jun 24 '11 at 12:23
  • is there any way to register the device for shake events again. like he is doing using NSNotificationCenter. – Rahul Vyas Jun 24 '11 at 12:25
  • i dont know exactly, i only know that motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event responds on a shake event. – Wasim Jun 24 '11 at 12:30
  • @Wasim if you can send your code by mail I can look into the issue. – Rahul Vyas Jun 24 '11 at 12:33
  • its a huge code rahul cant send the whole code sorry. Can you just tell me that how can i handle this responder issue :( – Wasim Jun 24 '11 at 13:19
  • @Wasim just create a demo with your flip side view and normal view where you are using shake motion. – Rahul Vyas Jun 24 '11 at 15:21
  • I got the answer for my actual problem rahul . Thanks a lot for your help also :) – Wasim Jun 24 '11 at 16:05

1 Answers1

1

Just use viewWillDissappear method not viewDidDissappear.

Ali
  • 26
  • 1
  • This worked for me perfectly I was doing mistake in using ViewDidDisappear method, instead use ViewWillDissappear and it will all work fine :) ` -(void) viewWillDisappear: (BOOL) animated{ [self resignFirstResponder]; [super viewWillDisappear:animated]; }` also you can add this line in your app deletage `- (void)applicationDidFinishLaunching:(UIApplication *)application { application.applicationSupportsShakeToEdit = YES; ` Happy Coding..! – Wasim Jun 24 '11 at 16:03