下拉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;// 系數(shù) 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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容