First look at the effect of the original app
Implementation process
The main thing is to view add one to the scrolling view in to KVO monitor its slide, and then offset do the operation according to it, the following is the code
[Mytableview addobserver:self forkeypath:@ "Contentoffset" options:nskeyvalueobservingoptionold| Nskeyvalueobservingoptionnew Context:nil];
tableViewafter obtaining the contentOffset logical judgment according to the specific requirements
-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: (nsdictionary<nsstring *,id> *) Change context: (void *) Context {if ([object Isequal:mytableview] && [keypath isequaltostring:@ "Contentoffset"]
{//Get new value old value cgfloat newy = [change[@ ' new '] cgpointvalue].y;
CGFloat oldy = [change[@ "old"] cgpointvalue].y;
float i = newy-oldy;//Drop-down is the new value is less than the old value, so i<0 is the Drop-down i>0 is the upper sliding NSLog (@ "%f", MYTABLEVIEW.CONTENTOFFSET.Y); if (Mytableview.contentoffset.y > -64 && mytableview.contentoffset.y <= 24) {//Boundary condition, not exact here if (I <= 0 & amp;& _ishide = = no && SELF.NAVIGATIONCONTROLLER.NAVIGATIONBAR.FRAME.ORIGIN.Y = 20) {//dropdown +bar already displayed status, no longer moved
Move return;
} _ishide = NO; Setting the Navigationbar frame allows him to slide according to TableView self.navigationController.navigationBar.frame = CGRectMake (0, -44-mytablev
Iew.contentoffset.y, Self.view.bounds.size.width, 44); Control transparency Self.navigationController.navigationBar.alpha =-mytableview.contentoFFSET.Y/64;
}else if (Mytableview.contentoffset.y >) {if (i > 10) {//change the value size to control the sliding speed of the triggering navigation bar _ishide = YES;
}else if (i < -10) {_ishide = NO;
} [Self.navigationcontroller setnavigationbarhidden:_ishide animated:yes]; }
}
Complete the effect diagram
Summarize
In fact, this effect is not really difficult to achieve, write this is mainly for everyone to see my realization process and ideas, hope can help everyone. If you have any questions, please leave a message, thank you for your support to the cloud-dwelling community.