国产探花免费观看_亚洲丰满少妇自慰呻吟_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 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 望城县| 武威市| 米易县| 乳源| 汕尾市| 深圳市| 两当县| 富源县| 五常市| 乌拉特中旗| 柳河县| 绥棱县| 嵩明县| 阳原县| 邢台市| 梧州市| 册亨县| 特克斯县| 外汇| 营口市| 监利县| 临沭县| 敦化市| 孟津县| 中卫市| 化州市| 买车| 潞城市| 三明市| 大丰市| 肇东市| 霍林郭勒市| 潞西市| 承德县| 密云县| 宁强县| 江山市| 三都| 武隆县| 通许县| 贡觉县|