ios - How to add PageviewController inside collectionview -


i have uicollectionview inside uiviewcontroller. now, need add uipageviewcontroller inside custom uicollectionviewcell created. how can ?

here's approach.

uiviewcontroller.h class

-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath{          pviewcollectionviewcell *cell=[collectionview dequeuereusablecellwithreuseidentifier:@"cell" forindexpath:indexpath];          [cell.pageviewcontroller addtarget:self action:@selector(changed:) forcontrolevents:uicontroleventtouchupinside];          return cell;  } 

pviewcollectionviewcell.h class

#import <uikit/uikit.h>    @interface pviewcollectionviewcell : uicollectionviewcell <uipageviewcontrollerdatasource>  @property (strong, nonatomic) iboutlet uiimageview *pagebannerimageview;  @property (strong, nonatomic) iboutlet uipagecontrol *pageviewcontroller;  - (ibaction)pageviewchanged:(id)sender;    @end 

you asking "how implement uipageviewcontroller" , giving code example uipagecontrol. different thing. never recommend implementing uipageviewcontroller on uicollectionviewcell, because might kill performance. best approach uiscrollview + uipagecontrol.

on uicollectionviewcell add uiscrollviewdelegate:

- (void)scrollviewdidscroll:(uiscrollview *)scrollview {     cgfloat pagewidth = scrollview.frame.size.width;     int page = floor((scrollview.contentoffset.x - pagewidth / 2) / pagewidth) + 1;     self.pagecontrol.currentpage = page; } 

also, enable paging on scroll using:

self.scrollview.pagingenabled = yes; 

here can find many answers described. not matter implement pagination - on uiview or uicollectionviewcell. thing should make sure uicollectionview scroll gesture not cancel uicollectionview pagination scroll gesture.

please, not duplicate questions. first have on existing posts , create own 1 if did not find anything.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -