我正在实现一个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;
}
答案 0 :(得分:1)
你需要为动画使用块,所以喜欢它:(注意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.