ios - UICollectionView pageing and swipe -
i'm looking if 4 directions possible swipe.
can example code app : link
or idea?
i making controller use uicollectionview.
- (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return [seccollectionimagesarray count]; nslog(@"seccollectionimagesarray is:%@ ",seccollectionimagesarray); } - (mycell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { mycell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"cell" forindexpath:indexpath]; uiimageview *recipeimageview = (uiimageview *)[cell viewwithtag:100]; uilabel *desclabel = (uilabel *)[cell viewwithtag:110]; [desclabel settext:[seccollectionimagesarray objectatindex:indexpath.row]]; recipeimageview.image = [uiimage imagenamed:[seccollectionimagesarray objectatindex:indexpath.row]]; int pages = floor(collectionview.contentsize.width / collectionview.frame.size.width) + 1; [pagecontrol setnumberofpages:pages]; return cell; } -(void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { third=[[thirdviewcontroller alloc]initwithnibname:@"thirdviewcontroller" bundle:nil]; third.recipeimagedname=[seccollectionimagesarray objectatindex:indexpath.row]; [self presentviewcontroller:third animated:yes completion:nil]; } //write in thirdviewcontroller viewdidload currentindex=0; eachimgview.image=[uiimage imagenamed:recipeimagedname]; alloc]initwithnibname:@"secondviewcontroller" bundle:nil]; _second.seccollectionimagesarray=dataarray; nslog(@"dataarray:%@",dataarray); uiswipegesturerecognizer *swipeleft = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipe:)]; uiswipegesturerecognizer *swiperight = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipe:)]; [swipeleft setnumberoftouchesrequired:1]; [swipeleft setdirection:uiswipegesturerecognizerdirectionleft]; [swiperight setnumberoftouchesrequired:1]; [swiperight setdirection:uiswipegesturerecognizerdirectionright]; [self.eachimgview addgesturerecognizer:swipeleft]; [self.eachimgview addgesturerecognizer:swiperight]; } -(void)handleswipe:(uiswipegesturerecognizer*)sender { nslog(@"swiped :"); nslog(@"total item %ld ",(long)dataarray.count); nsinteger index = currentindex; if (sender.direction == uiswipegesturerecognizerdirectionleft) { index++; } else if (sender.direction == uiswipegesturerecognizerdirectionright) { index--; } if (index > 0 || index < ([dataarray count] - 1)) { if (index== dataarray.count) { index=0; } currentindex = index; [self showimageatindex:currentindex]; } else { if (index < 0) { index=dataarray.count-1; currentindex = index; [self showimageatindex:currentindex]; } currentindex = index; [self showimageatindex:currentindex]; nslog(@"reached end, swipe in opposite direction"); } }
i hope code works you
Comments
Post a Comment