Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 摇动后如何调用google页面_Ios_Objective C_Iphone_Method Call_Handshaking - Fatal编程技术网

Ios 摇动后如何调用google页面

Ios 摇动后如何调用google页面,ios,objective-c,iphone,method-call,handshaking,Ios,Objective C,Iphone,Method Call,Handshaking,我试着在摇过iPhone后给谷歌页面打电话。我试着这样做 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if(event.type == UIEventSubtypeMotionShake) { [self shakemethod]; [self open]; } } -(void)shakemethod { CABasicAnimation

我试着在摇过iPhone后给谷歌页面打电话。我试着这样做

- (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"]];
}
两种方法都有效,但当我摇动iPhone时,摇动图像不显示,但谷歌页面打开 所以请帮帮我。我需要在我摇动手机时先摇动图像,摇动完成后摇动打开谷歌页面


提前谢谢

将delgate self设置为抖动动画,然后在动画完成时调用open方法

- (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"]];
    }
希望这是你想要的