ios - 在 ios 中的动画期间,对 imageview 的手势不起作用

标签 ios objective-c animation uiviewanimation

我正在实现一个 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/

相关文章:

objective-c - 核心数据删除规则

android - Android 浏览器中的复制 Canvas 动画

ios - 每个线程使用的内存量

ios - 火力地堡存储 : child() doesn't work with iOS App

iphone - 检查 iPhone 中的麦克风音量

objective-c - 如何优化压缩和上传文件的循环

javascript - 如何在使用.stop时让.slideDown和.slideUp完成动画?

ios - UIImageView 停止动画

ios - Xamarin:无法安装应用程序 AMDeviceSecureInstallApplicationBundle 返回:0xe8008015

objective-c - CALayer 子类中的颜色属性