下拉tableView放大图片

#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;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容