国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS tableView實現(xiàn)頂部圖片拉伸效果

2019-10-21 18:41:11
字體:
來源:轉載
供稿:網友

大家可能注意到一些app的tableView的頂部圖片,會隨著你拉伸而跟著拉伸變大,下面這是我的一些想法

原圖:

iOS,tableView,頂部圖片拉伸

效果圖:

iOS,tableView,頂部圖片拉伸

下面附上代碼吧,這里的圖片不是添加在tabview的header上

#define SCREEN_W [UIScreen mainScreen].bounds.size.width #define SCREEN_H [UIScreen mainScreen].bounds.size.height #define TOP 200 //頂部預留  #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ù)圖片原有尺寸進行顯示 將多余部分切除  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;   //保持圖片原點仍為屏幕左上方   f.origin.y = offSet;   //保證圖片根據(jù)滑動高度拉伸   f.size.height = -offSet;   //給圖片重新設置坐標   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 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 庆城县| 邯郸市| 张家界市| 通河县| 云浮市| 营口市| 台北县| 临夏市| 修文县| 贵阳市| 武义县| 石河子市| 屏东县| 洪湖市| 五指山市| 札达县| 布拖县| 山西省| 体育| 万宁市| 绥滨县| 平顺县| 崇信县| 会理县| 韶山市| 翼城县| 开远市| 密云县| 罗源县| 酒泉市| 萨迦县| 洛川县| 崇文区| 二手房| 红桥区| 名山县| 福安市| 南漳县| 丰宁| 玉树县| 乌苏市|