IOS: The use of suspended condition filter drop-down boxes

Source: Internet
Author: User

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

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.