ios - Content offset stays constant -


i've got uipageviewcontroller in app, set this:

self.pageviewcontroller = [self.storyboard instantiateviewcontrollerwithidentifier:@"mainpageviewcontroller"]; self.pageviewcontroller.datasource = self; self.pageviewcontroller.delegate = self; self.pageviewcontroller.view.frame = cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [self addchildviewcontroller:self.pageviewcontroller]; [self.view addsubview:self.pageviewcontroller.view]; [self.pageviewcontroller didmovetoparentviewcontroller:self]; 

i've made uiviewcontroller conform uiscrollviewdelegate , added code set scrollview delegate self:

    (uiview *currentview in self.pageviewcontroller.view.subviews) {     if ([currentview iskindofclass:[uiscrollview class]]) {         uiscrollview *scrollview = (uiscrollview *)currentview;         scrollview.delegate = self;         break;     } } 

then i'm trying use method find current page, though contentoffset stays same whenever scroll uipageviewcontroller:

-(void)scrollviewdidenddecelerating:(uiscrollview *)scrollview { cgfloat pagewidth = scrollview.frame.size.width; nsinteger page = scrollview.contentoffset.x / pagewidth;  nslog(@"content offset.x: %.f", scrollview.contentoffset.x); } 

why this?

i made work using delegate method of uipageviewcontroller rather scrollview. solution:

-(void)pageviewcontroller:(uipageviewcontroller *)pageviewcontroller didfinishanimating:(bool)finished previousviewcontrollers:(nsarray<uiviewcontroller *> *)previousviewcontrollers transitioncompleted:(bool)completed {     if (completed) {         nsinteger currentindex = [self.navviewcontrollers indexofobject:pageviewcontroller.viewcontrollers[0]];     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -