Question

I have a multiple images to show in imageview using cross dissolve animation and taping on image displays detail about image. Following is the code working but tap on imageview is failing when it's animating from one image to another.

Code for attaching single tap gesture recogniser to UIImageview and starting animation timer.

    self.imageView.userInteractionEnabled = YES;
    self.singleTapGestureRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showDetails)];
    self.singleTapGestureRecogniser.numberOfTapsRequired = 1;
    self.singleTapGestureRecogniser.cancelsTouchesInView = NO;

    [self.imageView addGestureRecognizer:self.singleTapGestureRecogniser];

    [self startAnimationTimer];

- (void)startAnimationTimer
{
    if(!self.timer && ![self.timer isValid]) {
        self.timer  =  [NSTimer scheduledTimerWithTimeInterval:5.0
                                target:self
                                selector:@selector(startAnimation)
                                userInfo:nil
                                repeats:YES];
        [self.timer fire];
    }
}

Single tap on imageview works fine unless following code is executing! I have to tap 3-4 times to open details about image.

- (void)startAnimation
{
    [UIView transitionWithView:self.imageView duration:2.0
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^ {
                        currentImageIndex = ++currentImageIndex % self.images.count;
                        [self.imageView setImage:[[self.images objectAtIndex:currentImageIndex] image]];
                    } completion:^(BOOL finished) {
                    }
     ];
}

Could someone please suggest me how to get rid of this issue please.

Was it helpful?

Solution

set UIViewAnimationOptionAllowUserInteraction in the options like so

 [UIView transitionWithView:self.imageView duration:2.0
                       options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction
                    animations:^ {
                        currentImageIndex = ++currentImageIndex % self.images.count;
                        [self.imageView setImage:[[self.images objectAtIndex:currentImageIndex] image]];
                    } completion:^(BOOL finished) {
                    }
     ];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top