iphone - Getting Image index -
i developing app in have 15 images stored in array front images , 15 images image. want add image scrollview vertically have done problem how can compare 2 array images.
adding front images on vertical scrollview added succesfully not randomly shuffled, ie when double tap on front image array image displayed still front image present in imageview.
please me out solve problem.
thanks in advance.
please check code :
- (void)viewdidload { [super viewdidload]; appdelegate * delegate=(appdelegate *)[[uiapplication sharedapplication]delegate]; delegate.front=true; delegate.back=false; uiscrollview *scrollview=[[uiscrollview alloc]initwithframe:cgrectmake(0, 0, 320, 480)]; [scrollview setpagingenabled:yes]; [scrollview setshowshorizontalscrollindicator:no]; frontscards=[[nsmutablearray alloc]initwithobjects:@"cloub1.png",@"cloub2.png",@"cloub3.png",@"cloub4.png",@"cloub5.png",@"cloub6.png",@"cloub7.png",@"cloub8.png",@"cloub9.png",@"cloub10.png",@"cloub11.png",@"cloub12.png",@"diamond1.png",@"diamond2.png",@"diamond3.png",@"diamond4.png",@"diamond5.png", nil]; for(int m=0; m<[frontscards count];m++) { imgview.tag=m; int randidx=arc4random()%[frontscards count]; nsstring *imagename=[frontscards objectatindex:randidx]; // nslog(@"%d",randidx); nsstring *fullimagename=[nsstring stringwithformat:@"%@",imagename]; int padding=25; // padding given. cgrect imageviewframe=cgrectmake(scrollview.frame.size.width*m+padding, scrollview.frame.origin.y, scrollview.frame.size.width-2*padding, scrollview.frame.size.height); imgview=[[uiimageview alloc]initwithframe:imageviewframe]; [imgview setimage:[uiimage imagenamed:fullimagename]]; [imgview setcontentmode:uiviewcontentmodescaleaspectfill]; [scrollview addsubview:imgview]; uitapgesturerecognizer *doubletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(doubletapimgview:)]; doubletap.numberoftapsrequired = 2; doubletap.delegate = self; [self.imgview addgesturerecognizer:doubletap]; self.imgview.userinteractionenabled=yes; } cgsize scrollviewsize=cgsizemake(scrollview.frame.size.width*[frontscards count], scrollview.frame.size.height); [scrollview setcontentsize:scrollviewsize]; [self.view addsubview:scrollview]; } - (void)doubletapimgview:(uitapgesturerecognizer *)gesture { appdelegate * delegate=(appdelegate *)[[uiapplication sharedapplication]delegate]; delegate.back=true; delegate.front=false; nslog(@"%d", gesture.view.tag); nslog(@"double-tap"); backcards =[[nsmutablearray alloc]initwithobjects:@"card1.jpg",@"card2.jpg",@"card3.jpg",@"card4.jpg", nil]; uiscrollview *scrollview=[[uiscrollview alloc]initwithframe:cgrectmake(0, 0, 320, 480)]; [scrollview setpagingenabled:yes]; [scrollview setshowshorizontalscrollindicator:no]; for(int m=0; m< [backcards count];m++) { nsstring *imagename=[backcards objectatindex:m]; nsstring *fullimagename=[nsstring stringwithformat:@"%@",imagename]; int padding=25; // padding given. cgrect imageviewframe=cgrectmake(scrollview.frame.size.width*m+padding, scrollview.frame.origin.y, scrollview.frame.size.width-2*padding, scrollview.frame.size.height); imgview=[[uiimageview alloc]initwithframe:imageviewframe]; [imgview setimage:[uiimage imagenamed:fullimagename]]; [imgview setcontentmode:uiviewcontentmodescaleaspectfill]; [scrollview addsubview:imgview]; uitapgesturerecognizer *doubletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(doubletapimgview:)]; doubletap.numberoftapsrequired = 2; doubletap.delegate = self; [self.imgview addgesturerecognizer:doubletap]; self.imgview.userinteractionenabled=yes; } cgsize scrollviewsize=cgsizemake(scrollview.frame.size.width*[frontscards count], scrollview.frame.size.height); [scrollview setcontentsize:scrollviewsize]; [self.view addsubview:scrollview]; }
for achieving 1 can set tag
value every image when tap on particuler image you'l tag value , use tag
value.
self.imagview.tag=unique_tagvalue;
when click on image can set image array.
self.imageview.image=[uiimage imagenamed:[backarray objectatindex:self.imageview.tag]];
edit:-
in viewdidload
method set tags imageview this, imgview.tag=m+100;
keep below code in doubletapimgview
method
for(int m=0; m< [backcards count];m++) { uiimageview *imgview=(uiimageview *)[scrollview viewwithtag:m+100]; imgview.image=[uiimage imagnamed:[backcards objectatindex:m]]; }
subview translation:-
[self.view bringsubviewtofront:frontview];
Comments
Post a Comment