iosobjective-ciphonehttp-redirectuianimation

how to Redirect google page after method calling


I am tried to after completed animation redirect to Google page I tried like this ;

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    
    [self close];
    [self.audioPlayer2 play];
    [self open];
}
-(void)close
{
    CABasicAnimation *shake1 = [CABasicAnimation animationWithKeyPath:@"position1"];
    [shake1 setDuration:1.6];
    [shake1 setRepeatCount:1];
    [shake1 setAutoreverses:YES];
    
    [shake1 setDelegate:self];
    
    firstView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
    secondView.frame=CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
    [firstView.layer addAnimation:shake1 forKey:@"position1"];
    [secondView.layer addAnimation:shake1 forKey:@"position1"];

}
-(void)open
{ [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://google.co.in"]];
}

But my Problem is Close method not completed but open method is called. But I need after completed Closed method and then call to Open method

Can you tell me what wrong in my code?


Solution

  • I have changed the your code once check whether your issue resolved

    -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
    {
    
        [self close];
        [self.audioPlayer2 play];
    
    }
    -(void)close
    {
      [CATransaction begin];
        CABasicAnimation *shake1 = [CABasicAnimation animationWithKeyPath:@"position1"];
        [shake1 setDuration:1.6];
        [shake1 setRepeatCount:1];
        [shake1 setAutoreverses:YES];
    
        [shake1 setDelegate:self];
    
        firstView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
        secondView.frame=CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
    [CATransaction setCompletionBlock:^{ [self open];}];
        [firstView.layer addAnimation:shake1 forKey:@"position1"];
        [secondView.layer addAnimation:shake1 forKey:@"position1"];
     [CATransaction commit];
    }
    -(void)open
    { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://google.co.in"]];
    }
    

    Here I have used CATransaction, it has a completion block handler.