IOS is similar to the drop-down header view of the QQ space table view to enlarge the effect. ios View

Source: Internet
Author: User

IOS is similar to the drop-down header view of the QQ space table view to enlarge the effect. ios View

UITableView is a subclass of UIScrollView.
Therefore, the UIScrollView proxy method can also be applied on UITableView.
In this case, we can understand that in the drop-down process of the table, we need to make the image in the header appear slightly magnified. We can listen to events in a rolling view based on the scrolling view, you can change the size of the image by obtaining the amount of stretch from the drop-down list!

Therefore:

/*** Key processing: get the scroll offset from the scroll view to change the image changes */

The following code implements the effect:

@ Interface ViewController () <UITableViewDataSource, UITableViewDelegate> @ property (nonatomic, strong) UIImageView * headImageView; // header image @ property (nonatomic, strong) UITableView * tableView; // list @ property (nonatomic, strong) NSMutableArray * infoArray; // data source array @ end // screen width, high macro definition # define IPHONE_W ([UIScreen mainScreen]. bounds. size. width) # define IPHONE_H ([UIScreen mainScreen]. bounds. size. height) @ implementation ViewCont Rollerstatic CGFloat kImageOriginHight = 300;-(void) viewDidLoad {[super viewDidLoad]; // Add the view to the interface [self. view addSubview: self. tableView]; [self. tableView addSubview: self. headImageView] ;}# pragma mark -- proxy method of the rolling view-(void) scrollViewDidScroll :( UIScrollView *) scrollView {/*** key processing: get the scroll offset from the scroll view to change the image * // get the offset CGFloat yOffset = scrollView of the y value of the scroll view. contentOffset. y; NSLog (@ "yOffset = % f", yOffset); CGF Loat xOffset = (yOffset + kImageOriginHight)/2; if (yOffset <-kImageOriginHight) {CGRect f = self. headImageView. frame; f. origin. y = yOffset; f. size. height =-yOffset; f. origin. x = xOffset; // int abs (int I); // process the absolute value of the int type // double fabs (double I ); // process the absolute value of the double type // float fabsf (float I); // process the absolute value of the float type f. size. width = IPHONE_W + fabs (xOffset) * 2; self. headImageView. frame = f ;}# pragma mark -- table view proxy-(C GFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 44;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return self. infoArray. count;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * identify = @ "MyCellIndifer"; UITableViewCell * cell = [tableView de QueueReusableCellWithIdentifier: identify]; if (! Cell) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identify];} cell. textLabel. text = [self. infoArray objectAtIndex: indexPath. row]; return cell ;}# pragma mark -- get initialization operation-(UITableView *) tableView {if (_ tableView = nil) {_ tableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, IPHONE_W, IPHONE_H)]; _ tableView. delegate = self; _ tableView. dataSource = self; _ TableView. backgroundColor = [UIColor lightGrayColor]; // The content is displayed at kImageOriginHight. _ TableView. contentInset = UIEdgeInsetsMake (kImageOriginHight, 0, 0);} return _ tableView;}-(NSMutableArray *) infoArray {if (_ infoArray = nil) {_ infoArray = [[NSMutableArray alloc] init]; for (int I = 0; I <40; I ++) {[_ infoArray addObject: @ "this is a test! "] ;}} Return _ infoArray;}-(UIImageView *) headImageView {if (_ headImageView = nil) {_ headImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "111"]; _ headImageView. frame = CGRectMake (0,-kImageOriginHight, IPHONE_W, kImageOriginHight);} return _ headImageView ;}

Display:

About:
For details about how to set and use the scrolling views contentSize, contentOffset, and contentInset, you can view the scrolling views contentSize, contentOffset, and contentInset.

Demo download: Click here to download the demo.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.