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