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

首頁 > 系統 > iOS > 正文

iOS tableView實現頂部圖片拉伸效果

2020-07-26 02:28:00
字體:
來源:轉載
供稿:網友

大家可能注意到一些app的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;    //創建頂部圖片  UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -TOP, SCREEN_W, TOP)];  imageView.tag = 1000;    //更改圖片顯示模式 根據圖片原有尺寸進行顯示 將多余部分切除  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;   //保證圖片根據滑動高度拉伸   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 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴城市| 海淀区| 紫阳县| 上高县| 邵武市| 白水县| 江川县| 梁平县| 集安市| 清镇市| 曲周县| 平阳县| 获嘉县| 绿春县| 宜兰市| 天全县| 渝中区| 民乐县| 资中县| 巴彦淖尔市| 安远县| 巩留县| 安西县| 开原市| 越西县| 民乐县| 都兰县| 云阳县| 东丽区| 同江市| 平潭县| 沂水县| 苍梧县| 阳东县| 墨竹工卡县| 峨山| 公安县| 吉林市| 梅州市| 邢台县| 文水县|