iOS dev-uitableview top picture drop-down zoom in

Source: Internet
Author: User

About the top picture drop-down magnification, in the User Show Personal Center display user profile picture information, set UITableView Headerview implementation, UITableView inherit from Uiscrollview, The same settings uiscrollview the top picture can also achieve the same effect, a simple look at the effect of the implementation:

Set the required attribute variables in the controller:

@property  (strong,nonatomic)  uitableview  *tableview; @property  (strong,nonatomic)  Nsarray      *data; @property   (strong,nonatomic) UIView       *tableheaderview; @property  (strong,nonatomic)  Uiimageview  *imageview;

Initialize properties:

-(UITableView *) tableview{if (!_tableview) {_tableview=[[uitableview alloc]initwithframe:cgrectmake (0, 0,SCREE        Nwidth, ScreenHeight)];        _tableview.delegate=self;        _tableview.datasource=self;         _tableview.showsverticalscrollindicator=no; _tableview.autoresizingmask = Uiviewautoresizingflexibleheight |        Uiviewautoresizingflexiblewidth;    [_tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:cellidetifier]; } return _tableview;} -(UIView *) tableheaderview{if (!_tableheaderview) {_tableheaderview=[[uiimageview Alloc]initwithframe:cgrectma    Ke (0, 0,screenwidth, 100)]; } return _tableheaderview;} -(Uiimageview *) imageview{if (!_imageview) {_imageview=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, SCRE        Enwidth, 100)]; _imageview.autoresizingmask=uiviewautoresizingflexibleheight |        Uiviewautoresizingflexiblewidth;        _imageview.clipstobounds=yes; _imageview.contentmode=uiviewcontentmoDescaleaspectfill; } return _imageview;}

Uitableviewdelegate implementation:

-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{    return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{    return [self.data Count];} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    UITableViewCell  *cell=[tableview Dequeuereusablecellwithidentifier:cellidetifier];    [Cell.textlabel Settext:self.data[indexpath.row]];    return cell;}

Initialize ImageView in Viewdidload:

    [Email protected] [@ "Flyelephant", @ "blog Park" @ "UITableView image Amplification" @ "http://www.cnblogs.com/xiaofeixiang/"];    Self.imageview.image=[uiimage imagenamed:@ "Girl"];    Self.imageview.contentmode=uiviewcontentmodescaleaspectfill;    [Self.tableheaderview AddSubview:self.imageView];    Self.tableview.tableheaderview=self.tableheaderview;    [Self.view AddSubview:self.tableView];

In the process of uitableviewview downward pull, change the position of the ImageView:

-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{    cgpoint offset = scrollview.contentoffset;    if (Offset.y < 0) {        cgrect rect =self.tableheaderview.frame;        RECT.ORIGIN.Y = Offset.y;        Rect.size.height =cgrectgetheight (rect)-offset.y;        Self.imageView.frame = rect;        Self.tableheaderview.clipstobounds=no;}    }

It is simple to realize, and I hope to be helpful to those who need it.

iOS dev-uitableview top picture drop-down zoom in

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.