ios - What method do I use when wanting to display multiple images and respond to user interaction? -


alright, have 5 custom images want in game.

so each variable example have value set it, image 1 = 1, image 2 = 2, etc. want user able press 1 of these images , when do, change image 5 image 4.

do need put these images in array/dictionary/etc? have no idea how go dont know search on google.

any or advice appreciated.

you should use imageviews , add gesture recognizer each imageview, , give each imageview tags in order organize them. can set tags in storyboard pressing imageview , entering tag under shield. each imageview should have distinct tag. i'm giving programatic example below clarity, though.

uitapgesturerecognizer * tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(wastapped:)]; tap.delegate = self; imageview.tag = 1; [imageview addgesturerecognizer:tap]; 

when imageview tapped selector called , can change imageview so.

-(void) wastapped:(uigesturerecognizer *) recognizer  {     uiimageview * imageview = (uiimageview*) recognizer.view;     if (imageview.tag == 1){        // change image else        uiimage * newimage = [uiimage imagenamed:@"newimage"];        imageview.image = newimage;     }  } 

you may have call [imageview setneedsdisplay] make new image appear. have devise system organize imageviews. may have set imageview.userinteractionenabled yes.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -