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

首頁 > 系統 > 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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉荫县| 永定县| 三门县| 息烽县| 屯门区| 岑巩县| 商丘市| 陈巴尔虎旗| 澎湖县| 怀仁县| 泉州市| 北海市| 微博| 贵德县| 疏勒县| 民丰县| 易门县| 遂宁市| 巫溪县| 永川市| 大埔区| 青浦区| 囊谦县| 茂名市| 武安市| 永胜县| 富源县| 三明市| 汕头市| 崇信县| 长武县| 辽阳县| 文成县| 临湘市| 新乐市| 天镇县| 昆明市| 老河口市| 淮滨县| 东阳市| 顺义区|