#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
RootViewController *rootViewVc = [[RootViewController alloc] init];
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:rootViewVc];
self.window.rootViewController = rootNav;
[self.window makeKeyAndVisible];
return YES;
}
#import "RootViewController.h"
#define KScreenWidth [[UIScreen mainScreen]bounds].size.width
#define KScreenHeight [[UIScreen mainScreen]bounds].size.height
const CGFloat TopViewH = 168; // 图片的高度
@interface RootViewController ()
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIImageView *topView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
self.navigationItem.title = @"tableView下拉放大图片";
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - 64) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:_tableView];
self.tableView.contentInset = UIEdgeInsetsMake(TopViewH * 1, 0, 0, 0);
self.topView = [[UIImageView alloc] init];
self.topView.image = [UIImage imageNamed:@"User_Profiles_bg.png"];
self.topView.frame = CGRectMake(0, -TopViewH, KScreenWidth, TopViewH);
self.topView.contentMode = UIViewContentModeScaleAspectFill;
[self.tableView addSubview:_topView];
[self.tableView insertSubview:_topView atIndex:0];
// Do any additional setup after loading the view.
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat down = - (TopViewH * 1) - scrollView.contentOffset.y;
if (down < 0) {
return;
}
CGRect frame = self.topView.frame;
frame.size.height = TopViewH + down * 5;// 系数 5 决定速度
self.topView.frame = frame;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"测试%ld",indexPath.row];
return cell;
}