iOS tableView實(shí)現(xiàn)頂部圖片拉伸效果
大家可能注意到一些app的tableView的頂部圖片,會(huì)隨著你拉伸而跟著拉伸變大,下面這是我的一些想法
原圖:
效果圖:
下面附上代碼吧,這里的圖片不是添加在tabview的header上
#define SCREEN_W [UIScreen mainScreen].bounds.size.width #define SCREEN_H [UIScreen mainScreen].bounds.size.height #define TOP 200 //頂部預(yù)留 #import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> @property (nonatomic,strong)UITableView *tableV; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self creatTableView]; } - (void)creatTableView { self.automaticallyAdjustsScrollViewInsets = NO; self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H) style:UITableViewStylePlain]; self.tableV.contentInset = UIEdgeInsetsMake(TOP, 0, 0, 0); self.tableV.delegate = self; self.tableV.dataSource = self; //創(chuàng)建頂部圖片 UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -TOP, SCREEN_W, TOP)]; imageView.tag = 1000; //更改圖片顯示模式 根據(jù)圖片原有尺寸進(jìn)行顯示 將多余部分切除 imageView.contentMode = UIViewContentModeScaleAspectFill; //多余部分隱藏 imageView.clipsToBounds = YES; imageView.image = [UIImage imageNamed:@"pic"]; [self.view addSubview:_tableV]; [self.tableV addSubview:imageView]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { float offSet = scrollView.contentOffset.y; if (offSet < -200) { UIImageView * tempImageView = (UIImageView*)[self.view viewWithTag:1000]; CGRect f = tempImageView.frame; //保持圖片原點(diǎn)仍為屏幕左上方 f.origin.y = offSet; //保證圖片根據(jù)滑動(dòng)高度拉伸 f.size.height = -offSet; //給圖片重新設(shè)置坐標(biāo) tempImageView.frame = f; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cell = @"cell"; UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cell]; if (!myCell) { myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cell]; } myCell.textLabel.text = @"我是 cell"; return myCell; } @end
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS實(shí)現(xiàn)點(diǎn)擊圖片放大和長(zhǎng)按保存圖片的示例
- iOS 點(diǎn)擊圖片放大效果的實(shí)現(xiàn)
- 解決iOS11圖片下拉放大出現(xiàn)信號(hào)欄白條的bug問(wèn)題
- 利用iOS手勢(shì)與scrollView代理實(shí)現(xiàn)圖片的放大縮小
- iOS tableview實(shí)現(xiàn)頂部拉伸效果
- iOS TableView頭視圖根據(jù)偏移量下拉縮放效果
- iOS tableView實(shí)現(xiàn)頭部拉伸并改變導(dǎo)航條漸變色
- iOS應(yīng)用開發(fā)中UITableView的分割線的一些設(shè)置技巧
- IOS UITableView和UITableViewCell的幾種樣式詳細(xì)介紹
- iOS tableView實(shí)現(xiàn)下拉圖片放大效果
相關(guān)文章
IOS中快速集成短信SDK驗(yàn)證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機(jī)短信驗(yàn)證碼
這篇文章主要介紹了IOS中快速集成短信SDK驗(yàn)證開發(fā)(SMSSDK),IOS開發(fā)中如何設(shè)置手機(jī)短信驗(yàn)證碼 的相關(guān)資料,需要的朋友可以參考下2016-01-01iOS遍歷集合(NSArray、NSDictionary、NSSet)的方法總結(jié)
這篇文章主要介紹了iOS集合遍歷(NSArray、NSDictionary、NSSet)的方法,文中給出了詳細(xì)的方法示例,并總結(jié)了各個(gè)方法的優(yōu)缺點(diǎn)來(lái)供大家學(xué)習(xí)參考,需要的朋友們下面來(lái)一起看看吧。2017-03-03ios的collection控件的自定義布局實(shí)現(xiàn)與設(shè)計(jì)
這篇文章主要介紹了mac、iOS端支持自定義布局的collection控件的實(shí)現(xiàn)與設(shè)計(jì),需要的朋友學(xué)習(xí)參考下吧。2017-12-12關(guān)于iOS自帶九宮格拼音鍵盤和Emoji表情之間的一些坑
這篇文章主要給大家介紹了關(guān)于iOS自帶九宮格拼音鍵盤和Emoji表情之間的一些坑文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05ios通過(guò)SDWebImage實(shí)現(xiàn)圖片加載時(shí)的漸變效果
本篇文章主要介紹了ios通過(guò)SDWebImage實(shí)現(xiàn)圖片加載時(shí)的漸變效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04