2

I tried to call google page after shake iPhone. I tried like this:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if(event.type == UIEventSubtypeMotionShake)
    {
        [self shakemethod];
        [self open];
      
    }
}
-(void)shakemethod
{
CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
        [shake setDuration:1.1];
        [shake setRepeatCount:2];
        [shake setAutoreverses:YES];
        [shake setFromValue:[NSValue valueWithCGPoint:
                             CGPointMake(lockImage.center.x - 15,lockImage.center.y)]];
        [shake setToValue:[NSValue valueWithCGPoint:
                           CGPointMake(lockImage.center.x + 15, lockImage.center.y)]];
        [lockImage.layer addAnimation:shake forKey:@"position"];
}
-(void)open
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://google.co.in"]];
}

Two methods working but when i shake iPhone shaking image not showing but google page open. I need when I shake mobile first shake image, after shaking completed shaking Open to Google Page.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Pavan Alapati
  • 317
  • 1
  • 5
  • 17

1 Answers1

0

set the delgate self to your shake animation then at animation finish delgate call the open method

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if(event.type == UIEventSubtypeMotionShake)
    {
        [self shakemethod];

    }
}
-(void)shakemethod
{
CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
        [shake setDuration:1.1];
        [shake setRepeatCount:2];
        [shake setAutoreverses:YES];
       //set animation delgate to self
        [shake setDelegate:self];
        [shake setFromValue:[NSValue valueWithCGPoint:
                             CGPointMake(lockImage.center.x - 15,lockImage.center.y)]];
        [shake setToValue:[NSValue valueWithCGPoint:
                           CGPointMake(lockImage.center.x + 15, lockImage.center.y)]];
        [lockImage.layer addAnimation:shake forKey:@"position"];
}

   //when animation will finish call the open method
    -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
    {
            [self open];
    }
    -(void)open
    {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://google.co.in"]];
    }

Hope this is what you want.

iHulk
  • 4,869
  • 2
  • 30
  • 39