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