麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統 > iOS > 正文

iOS tableView實現下拉圖片放大效果

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

本文實例為大家分享了iOS實現下拉圖片放大效果展示的具體代碼,供大家參考,具體內容如下

#import "ViewController.h"#define kScreenbounds [UIScreen mainScreen].bounds#define kScreenWidth [UIScreen mainScreen].bounds.size.width#define kScreenHeight [UIScreen mainScreen].bounds.size.height// 宏定義一個高度#define pictureHeight 200@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) UITableView *tableView;@property (nonatomic, strong) UIImageView *pictureImageView;@property (nonatomic, strong) UIView *header;@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view, typically from a nib.    self.navigationItem.title = @"向下拉伸放大圖片";  // 下面兩個屬性的設置是與translucent為NO,坐標變換的效果一樣  self.edgesForExtendedLayout = UIRectEdgeNone;  self.automaticallyAdjustsScrollViewInsets = NO;  [self createTableView];  }- (void)createTableView{  self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];  _tableView.delegate = self;  _tableView.dataSource = self;  [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];    // 添加頭視圖 在頭視圖上添加ImageView  self.header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, pictureHeight)];  _pictureImageView = [[UIImageView alloc] initWithFrame:_header.bounds];  _pictureImageView.image = [UIImage imageNamed:@"picture"];  /*    重要的屬性設置   */  //這個屬性的值決定了 當視圖的幾何形狀變化時如何復用它的內容 這里用 UIViewContentModeScaleAspectFill 意思是保持內容高寬比 縮放內容 超出視圖的部分內容會被裁減 填充UIView  _pictureImageView.contentMode = UIViewContentModeScaleAspectFill;  // 這個屬性決定了子視圖的顯示范圍 取值為YES時,剪裁超出父視圖范圍的子視圖部分.這里就是裁剪了_pictureImageView超出_header范圍的部分.  _pictureImageView.clipsToBounds = YES;  [_header addSubview:_pictureImageView];  self.tableView.tableHeaderView = _header;  [self.view addSubview:_tableView];  }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{  return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];  cell.textLabel.text = @"向下拉我";  return cell;}- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    /**   * 這里的偏移量是縱向從contentInset算起 則一開始偏移就是0 向下為負 上為正 下拉   */    // 獲取到tableView偏移量  CGFloat Offset_y = scrollView.contentOffset.y;  // 下拉 縱向偏移量變小 變成負的    if ( Offset_y < 0) {      // 拉伸后圖片的高度      CGFloat totalOffset = pictureHeight - Offset_y;      // 圖片放大比例      CGFloat scale = totalOffset / pictureHeight;      CGFloat width = kScreenWidth;      // 拉伸后圖片位置      _pictureImageView.frame = CGRectMake(-(width * scale - width) / 2, Offset_y, width * scale, totalOffset);    }}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}@end

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


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久aa| 精品一区二区三区在线观看视频 | 91精品一区二区综合在线 | 国产亚洲精彩视频 | 视频一区免费观看 | 成人国产精品久久 | 红杏亚洲影院一区二区三区 | 欧美爱爱视频网站 | 成年片在线观看 | 日韩一级片免费 | 免费黄色小视频网站 | 久久久久久久99 | 亚洲第一页综合 | 日韩在线毛片 | 欧美日韩在线播放一区 | 国产成人aⅴ | 九草网| 国产一区二区三区黄 | 欧美毛片| 欧美一级做一级爱a做片性 久久久资源网 | 欧美一区二区网站 | 日韩视频一二区 | 亚洲成人自拍电影 | 黄a大片 | 妇子乱av一区二区三区 | 一区二区三区四区视频在线观看 | 国产一级毛片av | 久久久三区 | 毛片在线免费视频 | 成人国产精品一区 | 亚州综合| 成人444kkkk在线观看 | 国产在线中文 | 一本在线高清码电影 | 成品片a免费直接观看 | 亚洲成人精品在线 | 视频一区二区三区免费观看 | 91精品国产综合久久青草 | 91美女啪啪 | 国产大片免费看 | 久久久久久久久久久亚洲 |