E
E
eXhausted2012-07-06 15:59:46
Objective-C
eXhausted, 2012-07-06 15:59:46

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

When executing such code in imageViewFromEvent.image nil. Same as in IB UIImageView nil.
Tell me something :)
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
SAKRIST, 2012-07-06
@SAKRIST

Try to take content from CALayer like this imageViewFromEvent.layer.contents

N
No_Time, 2012-07-06
@No_Time

I myself faced such a problem. The problem was solved like this: stackoverflow.com/questions/5536915/fetching-image-from-animating-uiimageview

K
Krypt, 2012-07-08
@Krypt

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?

U
usgleb, 2012-07-10
@usgleb

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

Otherwise, write your own control, as Krypt advises you above . I think the latter option is more acceptable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question