0

I have used the animated images on image view concept. It is working fine.Now whenever when I touch that image view I want to check which image is placed on that image view. How should I do this. I have used the following code to make the images animated.

addimage.animationImages=[NSArray arrayWithObjects:  
                          [UIImage imageNamed:@"Softindia.png"],
                          [UIImage imageNamed:@"images.png"],
                          nil];

addimage.animationDuration=25.0;
addimage.animationRepeatCount=0;

[addimage startAnimating];
[self.view addSubview:addimage];

Now what should I do on the touch event of image view. Please provide me some solution to resolve this.

Thanks in advance.

Nitin
  • 1,966
  • 4
  • 22
  • 53

2 Answers2

0
    UITapGestureRecognizer *tapGesture =
        [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imagetap)] autorelease];
        [imgview addGestureRecognizer:tapGesture];


-(void)imagetap
{
   // your code what ever you want on touch
}
Dipen Chudasama
  • 3,063
  • 21
  • 42
0

I am affraid that there is no such property inside UIImage which help you to find image name. you can use this tricky method for solving your problem.

create an property

@property(nonatomic, retain) NSMutableArray * imageArray;

and then synthesis in .m file

@synthesis imageArray

afterward perform following action

self.imageArray = [[NSMutableArray alloc] init]; 
UIImage *myImage1 = [UIImage imageNamed:@"Softindia.png"];
[imageArray addObject:myImage1];

//Add Second Image
UIImage *myImage2 = [UIImage imageNamed:@"images.png"];
[imageArray addObject:myImage2];

addimage.animationImages= imageArray;

and where ever you are getting your image check do following action

UIImage image = addimage.image;
 index = [imageArray indexOfObject:image];
 if(index == 0){
  //Do action for softindia.png
 }
 else {
  //Do action for images.png;
 }
Sunil Pandey
  • 7,042
  • 7
  • 35
  • 48