Ios:tableview effect of the drop-down of the table head

Source: Internet
Author: User

Now many apps set this effect, how to achieve this effect, in fact, only need a simple two methods, then we directly on the code

First we drag a tableview in the storyboard and set the navigation, then we set the picture in TableView
I wrote a method of my own and then called it in viewdidload, or I can set it directly in the viewdidload.

Uiimageview *imageview = [[Uiimageview alloc]initwithframe:cgrectmake (00)]; [ImageView sd_setimagewithurl:[nsurl URLWithString:self.goods.image_default] placeholderimage:[uiimage imagenamed:  @ "crazy"=  ImageView;

Method One:

//ScrollView method views are called in real time when the view is sliding- (void) Scrollviewdidscroll: (Uiscrollview *) scrollview{cgfloat width=Self.view.frame.size.width; //Picture WidthCGFloat Yoffset =Scrollview.contentoffset.y; //the Y value of the offset    if(Yoffset <0) {cgfloat Totaloffset= $+ABS (Yoffset); CGFloat F= Totaloffset/ $; //The frame of the stretched picture should be scaled in the same scale. Self.tableView.tableHeaderView.frame = CGRectMake (-(width *f-width)/2, Yoffset, Width *F, Totaloffset); }}

Method Two:

-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{//Get offsetCgpoint offset =Scrollview.contentoffset; //decide whether to change    if(Offset.y <0) {CGRect rect=Self.tableView.tableHeaderView.frame; //We just need to change the Y-value and the height of the imageRECT.ORIGIN.Y =Offset.y; Rect.size.height= $-Offset.y; Self.tableView.tableHeaderView.frame=rect; }}

The effect is as follows:

Ios:tableview effect of the drop-down of the table head

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.