IOS Swift&oc emulate mainstream app for sliding view hidden navigation bar

Source: Internet
Author: User

Simple directly on the code-.-a GIF figure 5M?

@property (nonatomicstrongUITableView *tableViewScroll;@property (nonatomicassigndouble//记录滑动的距离@property (nonatomicstrongUIView *customView;@property (nonatomicstrongUIButton *btn;

Create the desired view

-(uitableview  *)        tableviewscroll{if  (_tableviewscroll = = nil ) { _tableviewscroll = [[uitableview  alloc] Initwithframe:cgrectmake (0 , 0 , ScreenWidth, ScreenHeight) Style:uitableviewstyleplain]        ;        _tableviewscroll.delegate  = self ;        _tableviewscroll.datasource  = self ; [_tableviewscroll registerclass:[uitableviewcell  class] Forcellreuseidentifier    : Cellidentifier]; } return  _tableviewscroll;}  
-(uiview  *) customview{if  (_customview = = nil ) {_custo MView = [[uiview  alloc] Initwithframe:cgrectmake (0        , 44 , ScreenWidth, 30 )]; _customview.backgroundcolor  = [UIColor     Lightgraycolor]; } return  _customview;}  
-(uibutton  *) btn{ If  (_btn = = nil ) {_btn = [uibutton  but Tonwithtype:uibuttontypecustom]; _btn.frame  = CGRectMake (ScreenWidth-70 , 5 , 40 , 20 ); [_btn settitle:@ "attention"  forstate:uicontrolstatenormal]; _btn.titlelabel  .font  = [uifont  systemfontofsize:13 ]; _btn.backgroundcolor  = [uicolor  GreenColor] ; } return  _btn;} 
The key is the processing in the ScrollView protocol method
//objective-c -( void ) Scrollviewdidenddecelerating: (uiscrollview  *) scrollview{//record sliding distance  self   = Scrollview.contentoffset  ; nslog  (@ "histroy_y ========%lf" , self  .recorddistance );} //Swift  func scrollviewdidenddecelerating (scrollView: uiscrollview ) {self  .recorddistance  = Scrollview.contentoffset  .y } 
//Objective-c- (void) Scrollviewdidscroll: (Uiscrollview*) scrollview{NSLog(@"y =======%lf", ScrollView. Contentoffset. Y); ScrollView. Contentoffset. Y> Self. Recorddistance? ScrollView. Contentoffset. Y< Self. Recorddistance? [ Self. NavigationcontrollerSetnavigationbarhidden:NOAnimated:YES]:[ Self. NavigationcontrollerSetnavigationbarhidden:YESAnimated:YES] : [ Self. NavigationcontrollerSetnavigationbarhidden:NOAnimated:YES];}//SwiftFunc Scrollviewdidscroll (ScrollView:Uiscrollview) {ScrollView. Contentoffset. Y> Self. Recorddistance? ScrollView. Contentoffset. Y< Self. Recorddistance? Self. Navigationcontroller?. Setnavigationbarhidden(false, Animated:true): Self. Navigationcontroller?. Setnavigationbarhidden(true, Animated:true) : Self. Navigationcontroller?. Setnavigationbarhidden(false, Animated:true); }

Omitted TableView-related code
in Viewdidload

 [Self.view     Addsubview:self.tableviewscroll ] [Self.navigationcontroller   addsubview:self.customview ]     [Self.customview  addsubview:self.btn    ] Self.title  = @ "This is a test page"   Self.navigationcontroller  .navigationBar  .bartintcolor  = [Uicolor lightgraycolor] ;

I think I can have a good, I want to apply for micro Boga v. Just a little Sir-.-hahaha.

IOS Swift&oc emulate mainstream app for sliding view hidden navigation bar

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.