Answer the question
In order to leave comments, you need to log in
How to get the current image in an animated UIImageView?
Let's say there is something like a banner. UIImageView, in it 4 pictures change animatedly. By clicking on each of them, a certain action should occur. How in - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event to find out which of the pictures the user has tapped?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if([event touchesForView:self.imageView])
{
NSLog(@"kartinku potrogali^^");
UITouch *eventTouch = )
{
UIImageView *imageViewFromEvent = (UIImageView *)eventTouch.view;
}
}
}
Answer the question
In order to leave comments, you need to log in
Try to take content from CALayer like this imageViewFromEvent.layer.contents
I myself faced such a problem. The problem was solved like this: stackoverflow.com/questions/5536915/fetching-image-from-animating-uiimageview
Hmm…
Wouldn't it be easier to create your own control? A descendant of UIView, in which, according to the running NSTimer (don't forget to stuff it into NSRunLoopCommonModes, otherwise there will be special effects), the pictures in the UIImageView put inside, or the UIImageView themselves, change?
If you want to implement through touchesBegan and get a bunch of garbage in one place, then you can do this:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(image1.frame, touchLocation))
{
NSLog(@"Tap to image1");
}
if (CGRectContainsPoint(image2.frame, touchLocation))
{
NSLog(@"Tap to image2");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question