1. Introduction
The application of conditional filtering view is a very common function, usually it with the tableview of the table head suspended scrolling use, click the button, will pop-up drop-down box display conditions, select a condition, the drop-down box is automatically hidden.
2, the following
Click to eject from the middle, then scroll tableview with the move, to the top on the hover, pull down still follow the scroll, always scroll the initial position on the stop ...
3. Realization method
First: Use the tableview of the grouping, but the type must be selected as plain, and the type itself has a suspension effect. If the group type, there is no suspension effect;
// set TableView style -(Instancetype) Initwithstyle: (uitableviewstyle) style{ return [ Super Initwithstyle:uitableviewstyleplain];}
Second: Calculate the distance from the group head to the bottom of the navigation bar. I will tableview 2 groups, the first set of section header height is 260px, row height 0.01, the second set of section header height is 39px, it is from the top of the navigation bar 260px.
Then: give the drop-down box a default frame,y= 260px + 39px = 299px, height=0. Then through [UIView animation ...] The animation modifies the value of the frame.
Ddhomeconditionview is a view that has been added TableView
// conditional view (requires setting 299 as the default Y value) _conditionview = [[Ddhomeconditionview alloc]initwithframe:cgrectmake (0 2990= YES;
-(void) buttoncilicked: (UIButton *) sender{ if (sender.selected) { [self Showconditionview:sender]; // Click Show } Else { [self hideconditionview]; // Click Hide Again }}
//Show Criteria View-(void) Showconditionview: (UIButton *) sender{//Save All the selected buttons if(![Self.buttongroup Containsobject:sender]) {[Self.buttongroup addobject:sender]; } //Show Criteria View[UIView animatewithduration:0.2animations:^{ if(Self.tableview.contentoffset.y >260) {//tableview upward scrolling distance greater than 260,y value of TableView y offset + high_conditionview.frame= CGRectMake (0, Self.tableview.contentoffset.y + the, Screen_width, the); }Else{_conditionview.frame= CGRectMake (0,299, Screen_width, the);//Fixed size} _conditionview.hidden=NO; }];}//Hide Conditional View-(void) hideconditionview{//Hide Conditional View[UIView animatewithduration:0.2animations:^{_conditionview.frame= CGRectMake (0,260, Screen_width,0); _conditionview.hidden=YES; } Completion:^(BOOL finished) {//Set all selected buttons to unchecked for(UIButton *btninchself.buttongroup) {[btn Setselected:no]; } //Clear Array All buttons[Self.buttongroup removeallobjects]; }];}
finally: The monitoring TableView scrolling, is actually the ScrollView scroll distance value Scrollview.contentoffset.y, judging whether it is larger than the 260px calculated above;
If it is greater than, the Y value of the drop-down box equals Scrollview.contentoffset.y + 39px, otherwise the Y value of the drop-down box is fixed equal to 260px + 39px = 299px.
#pragmamark-uiscrollviewdelegate-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{if(Scrollview.contentoffset.y >260) {//tableview upward scrolling distance greater than 260,y value of TableView y offset + high_conditionview.frame = CGRectMake (0, Scrollview.contentoffset.y + the, Screen_width, the); }Else{_conditionview.frame= CGRectMake (0,299, Screen_width, the);//Fixed size }}
I am original, welcome to share
IOS: The use of suspended condition filter drop-down boxes