我尝试将完成的动画重定向到Google页面后,我尝试过这样做;
-(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"]];
}
但是我的问题是Close方法没有完成但是调用open方法。但是我需要在完成Closed方法之后然后调用Open方法
请告诉我我的代码中有什么问题
感谢高级。
答案 0 :(得分:2)
我检查您的问题是否已解决后,我已更改了您的代码
-(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"]];
}
这里我使用了CATransaction,它有一个完成块处理程序。
答案 1 :(得分:0)
尝试放置完成块:
-(void)close:(void(^)(void))completion
{
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"];
completion();
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self close:^{
[self.audioPlayer2 play];
[self open];
}];
}