Pergunta

I am implementing animation of one imageView.In this animation my ballon image is going from bottom to top and I want to hide it if user will touch the balloon.But my gesture is not working during animation.Could anyone help me.Thanks in advance.

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);

this is the method for gesture.but this method is not calling.

-(void)handleTapFrom:(UIGestureRecognizer *)sender
{
  img.hidden = yes;  
}
Foi útil?

Solução

You need to use block for your animation so like it : (Note the UIViewAnimationOptionAllowUserInteraction, which is important)

[UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
    // Your animation here
} completion:^(BOOL finished) {
    // Once completed do stuff here;
}];

I let you set the other params like you want.

If you need to work prior to iOS 4.0, you will need to set your animation in a separate thread. Check here for more info.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top