IOS implementation up-slide hidden nvaigtionbar and Drop-down display effect _ios

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.