objective c - Show Navigation bar when Scrolling back to top. IOS -
currently have uicollection
in hide uinavigation
top bar when scroll downwards 40px. uinavigation
top bar appears 1 time again when scroll top.
this works want able show /hide uinavigation
top bar anytime user scrolls 40px , not when scroll top.
e.g when start scrolling top bar hides, scroll middle of uicollectionview , when strat scrolling top uinavigation
top bar shows again.
any ideas?
#pragma mark - uiscrollviewdelegate methods -(void)scrollviewdidscrolltotop:(uiscrollview *)scrollview { if([[[uidevice currentdevice] systemversion] floatvalue] < 7.0f){ return; } cgrect frame = self.navigationcontroller.navigationbar.frame; frame.origin.y = 20; } -(void)scrollviewdidscroll:(uiscrollview *)scrollview { if([[[uidevice currentdevice] systemversion] floatvalue] < 7.0f){ return; } cgfloat offsety = scrollview.contentoffset.y; cgfloat contentheight = scrollview.contentsize.height - 300; if (offsety > contentheight - scrollview.frame.size.height) { [self.homepaginator fetchnextpage]; } cgrect frame = self.navigationcontroller.navigationbar.frame; cgfloat size = frame.size.height - 25; if([scrollview.pangesturerecognizer translationinview:self.view].y < 0) { frame.origin.y = -size; if(self.navigationcontroller.navigationbar.items.count > 0){ [uiview animatewithduration:0.25 delay:0 options:uiviewanimationoptioncurveeaseinout | uiviewanimationoptionallowuserinteraction animations:^{ cgfloat navbarheight = 25.0f; cgrect frame = cgrectmake(0.0f, 0.0f, 320.0f, navbarheight); [self.navigationcontroller.navigationbar setframe:frame]; } completion:^(bool finished) { self.navigationitem.titleview.alpha = 0; self.piccingtitleicon.alpha = 0; self.navigationitem.rightbarbuttonitem = nil; }]; } } else if([scrollview.pangesturerecognizer translationinview:self.view].y > 0) { [uiview animatewithduration:0.5 delay:0 options:uiviewanimationoptioncurveeaseinout | uiviewanimationoptionallowuserinteraction animations:^{ cgfloat navbarheight = 64.0f; cgrect frame = cgrectmake(0.0f, 0.0f, 320.0f, navbarheight); [self.navigationcontroller.navigationbar setframe:frame]; self.navigationitem.titleview.alpha = 1; self.piccingtitleicon.alpha = 1; self.btnsearch = [[uibarbuttonitem alloc] initwithcustomview:self.searchiconbutton]; [self.navigationitem setrightbarbuttonitem:self.btnsearch]; } completion:^(bool finished) { [self performselector:@selector(addiconstonavbar) withobject:nil afterdelay:-1.0]; }]; } }
get starting content offset before user scrolls.
– scrollviewwillbegindragging:(uiscrollview *)scrollview { currentoffset = scrollview.contentoffset.y; } -(void)scrollviewdidscroll:(uiscrollview *)scrollview { cgfloat scrollpos = scrollview.contentoffset.y - currentoffset; if(scrollpos >= 40 || scrollpos <= -40 /* or whatever height of toolbar */){ //fully hide toolbar [uiview animatewithduration:2.25 animations:^{ [self.navigationcontroller setnavigationbarhidden:yes animated:yes]; }]; } else { //slide incrementally, etc. [self.navigationcontroller setnavigationbarhidden:no animated:yes]; } }
ios objective-c uiscrollview uinavigationbar uicollectionview
No comments:
Post a Comment