我正在实现一个 imageView 的动画。在这个动画中,我的气球图像是从下到上的,如果用户触摸气球,我想隐藏它。但是我的手势在动画期间不起作用。谁能帮助我。提前致谢。
img=[[UIImageView alloc]init];
img.frame=CGRectMake(150, 450, 50,50);
[self.view addSubview:img];
img.image=[UIImage imageNamed:@"ballon3.png"];
img.userInteractionEnabled=YES;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
tapGestureRecognizer.numberOfTapsRequired=1;
tapGestureRecognizer.delegate=self;
[img addGestureRecognizer:tapGestureRecognizer];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatCount:30];
[UIView setAnimationDuration:10];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
CGAffineTransform scaleTrans =
CGAffineTransformMakeScale(2, 2);
CGAffineTransform rotateTrans =
CGAffineTransformMakeRotation(angle * M_PI / 180);
img.transform = CGAffineTransformConcat(scaleTrans, rotateTrans);
img.center = CGPointMake(30,320);
这是手势的方法,但是这个方法没有调用。
-(void)handleTapFrom:(UIGestureRecognizer *)sender
{
img.hidden = yes;
}
最佳答案
您需要为动画使用 block ,如下所示:(注意 UIViewAnimationOptionAllowUserInteraction
,这很重要)
[UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
// Your animation here
} completion:^(BOOL finished) {
// Once completed do stuff here;
}];
我让你根据需要设置其他参数。
如果您需要在 iOS 4.0 之前工作,则需要在单独的线程中设置动画。 Check here for more info.
关于ios - 在 ios 中的动画期间,对 imageview 的手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21756493/