iphone - Do something to selected image in scroll view -


i try make following: horizontal list of images, can select , it. example flip image around x axis. know how rotate image. created scrollview , load images. added event handler when tap on image. don't know how tapped image. how code method tapped image?

- (void)viewdidload {     [super viewdidload];              img1 = [uiimage imagenamed:@"imgtest.jpg"];     img2 = [uiimage imagenamed:@"imgtest2.jpg"];      arrayofimages = [[nsmutablearray alloc] init];     [arrayofimages addobject:img1];     [arrayofimages addobject:img2];     [arrayofimages addobject:img1];     [arrayofimages addobject:img2];      scrollview = [[uiscrollview alloc] init];     scrollview.scrollenabled = yes;     scrollview.pagingenabled = yes;     scrollview.directionallockenabled = yes;     scrollview.showsverticalscrollindicator = no;     scrollview.showshorizontalscrollindicator = no;     scrollview.delegate = self;     scrollview.backgroundcolor = [uicolor bluecolor];     scrollview.autoresizessubviews = yes;     scrollview.frame = cgrectmake(0, 0, 320, 128);     [self.view addsubview:scrollview];      uiimage *imagetoadd;     int x = 0;     int y = 0;     for(imagetoadd in arrayofimages)     {         uiimageview *temp = [[uiimageview alloc] initwithimage:imagetoadd];               temp.frame = cgrectmake(x, y, 128, 128);         temp.userinteractionenabled = yes;               x += 135;           uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(imagetapped:)];         [temp addgesturerecognizer:tap];              [scrollview addsubview:temp];     } ...  - (void)imagetapped:(uigesturerecognizer *)sender {      // how reference on selected item in scrollview???    } 

a gesture recognizer has view property returns view associated recognizer. since know it'll uiimageview can cast , use in:

uiimageview *iv = (uiimageview *)[sender view]; 

and image can queried via:

uiimage *image = [iv image]; 

if need know index in array, there 2 ways: either use [arrayofimages indexofobject:image];, or can assign tags (numbers) views , use them. tag not used apple, it's here developers can "mark" views in way. example:

nsinteger counter = 0; for(imagetoadd in arrayofimages) {     uiimageview *temp = [[uiimageview alloc] initwithimage:imagetoadd];     count.tag = counter++;     ... } 

then, in imagetapped:, can query index via tag:

nsinteger index = [imageview tag]; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -