IOS-tableview top stretch effect (Avatar stretch)
For example, to explore the stretching effect of the personal information interface, zoom in the drop-down Avatar
/// PersonController. m // Spread /// Created by qiuxuewei on 16/3/21. // Copyright? Qiu xuewei. All rights reserved. // # import "PersonController. h" @ interface PersonController ()
{} // Attribute list/** top Image view */@ property (nonatomic, strong) UIImageView * headerImageView; @ property (nonatomic, strong) UIView * headerBackView; /** personal information interface */@ property (nonatomic, strong) UITableView * tableView; @ end @ implementation PersonController # pragma mark-lazy loading-(UIView *) headerBackView {if (_ headerBackView = nil) {_ headerBackView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, kScreenWidth, 200)]; [_ hea DerBackView setBackgroundColor: [UIColor lightGrayColor];} return _ headerBackView;}-(UIImageView *) headerImageView {if (_ headerImageView = nil) {_ headerImageView = [[UIImageView alloc] init]; [_ headerImageView setImage: [UIImage imageNamed: @ "Qiu _ life. JPG "]; [_ headerImageView setBackgroundColor: [UIColor greenColor]; [_ headerImageView setContentMode: UIViewContentModeScaleAspectFill]; [_ headerImageVi Ew setClipsToBounds: YES];} return _ headerImageView;}-(UITableView *) tableView {if (_ tableView = nil) {_ tableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, kScreenWidth, kScreenHeight) style: UITableViewStyleGrouped]; [_ tableView setDataSource: self]; [_ tableView setDelegate: self];} return _ tableView ;} -(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading The view from its nib. // Add a subview [self addChildViews];} # pragma mark-class method // Add a subview-(void) addChildViews {// Add a table [self. view addSubview: self. tableView]; // Add an avatar image [self addHeaderImageView];} // Add an Avatar-(void) addHeaderImageView {[self. tableView setTableHeaderView: self. headerBackView]; [self. headerImageView setFrame: self. headerBackView. bounds]; [self. headerBackView addSubview: self. headerImageView] ;}# pragma mark -UITableViewDataSource-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return 4;}-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 2 ;} -(CGFloat) tableView :( UITableView *) tableView succeeded :( NSIndexPath *) indexPath {return 64;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// If this clause is not added, When you click "back" in the second-level column, the row is changed from selected to unselected. // Add this sentence, and the returned result is directly unselected. [TableView deselectRowAtIndexPath: indexPath animated: YES];} // initialize cell-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * ID = @ "cell"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: ID]; if (! Cell) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: ID];} // initialize cell data! [Cell. textLabel setText: @ "A wei"]; [cell. detailTextLabel setText: @ "2016-03-22"]; return cell;} // after rolling tableview is complete-(void) scrollViewDidScroll :( UIScrollView *) scrollView {// The Image Height CGFloat imageHeight = self. headerBackView. frame. size. height; // Image Width CGFloat imageWidth = kScreenWidth; // CGFloat imageOffsetY = scrollView. contentOffset. y; NSLog (@ "image up/down offset imageOffsetY: % f->", imageOffsetY); // move up if (imageOffsetY <0) {CGFloat totalOffset = imageHeight + ABS (imageOffsetY); CGFloat f = totalOffset/imageHeight; self. headerImageView. frame = CGRectMake (-(imageWidth * f-imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset);} // move down // if (imageOffsetY> 0) {// CGFloat totalOffset = imageHeight-ABS (imageOffsetY); // CGFloat f = totalOffset/imageHeight; // [self. headerImageView setFrame: CGRectMake (-(imageWidth * f-imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset)]; //}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end