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

首頁 > 系統 > iOS > 正文

iOS tableview實現頂部拉伸效果

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

本文實例為大家分享了iOS tableview頭部拉伸效果展示的具體代碼,例如探探個人信息界面拉伸效果,下拉頭像放大

iOS,tableview,頂部拉伸,iOS頂部拉伸,iOS拉伸效果

代碼:

//// PersonController.m// Spread//// Created by qiuxuewei on 16/3/21.// Copyright © 2016年 邱學偉. All rights reserved.//#import "PersonController.h"@interface PersonController ()<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>{}//屬性列表/** 頂部圖片視圖 */@property (nonatomic, strong) UIImageView *headerImageView;@property (nonatomic, strong) UIView *headerBackView;/** 個人信息界面 */@property (nonatomic, strong) UITableView *tableView;@end@implementation PersonController#pragma mark - 懶加載-(UIView *)headerBackView{ if (_headerBackView == nil) {  _headerBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];  [_headerBackView setBackgroundColor:[UIColor lightGrayColor]]; } return _headerBackView;}-(UIImageView *)headerImageView{ if (_headerImageView == nil) {  _headerImageView = [[UIImageView alloc] init];  [_headerImageView setImage:[UIImage imageNamed:@"邱_生活.JPG"]];  [_headerImageView setBackgroundColor:[UIColor greenColor]];  [_headerImageView setContentMode:UIViewContentModeScaleAspectFill];  [_headerImageView setClipsToBounds:YES]; } return _headerImageView;}-(UITableView *)tableView{ if (_tableView == nil) {  _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];  [_tableView setDataSource:self];  [_tableView setDelegate:self]; } return _tableView;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. //添加子視圖 [self addChildViews];}#pragma mark - 類內方法//添加子視圖-(void)addChildViews{ //添加表格 [self.view addSubview:self.tableView]; //添加頭像圖片 [self addHeaderImageView];}//添加頭像-(void)addHeaderImageView{ [self.tableView setTableHeaderView:self.headerBackView]; [self.headerImageView setFrame:self.headerBackView.bounds]; [self.headerBackView addSubview:self.headerImageView];}#pragma mark - UITableViewDataSource- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 4;}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2;}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 64;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 不加此句時,在二級欄目點擊返回時,此行會由選中狀態慢慢變成非選中狀態。 // 加上此句,返回時直接就是非選中狀態。 [tableView deselectRowAtIndexPath:indexPath animated:YES];}//初始化cell-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) {  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } //初始化cell數據! [cell.textLabel setText:@"阿偉"]; [cell.detailTextLabel setText:@"2016-03-22"]; return cell;}//滾動tableview 完畢之后-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ //圖片高度 CGFloat imageHeight = self.headerBackView.frame.size.height; //圖片寬度 CGFloat imageWidth = kScreenWidth; //圖片上下偏移量 CGFloat imageOffsetY = scrollView.contentOffset.y; NSLog(@"圖片上下偏移量 imageOffsetY:%f ->",imageOffsetY); //上移 if (imageOffsetY < 0) {  CGFloat totalOffset = imageHeight + ABS(imageOffsetY);  CGFloat f = totalOffset / imageHeight;  self.headerImageView.frame = CGRectMake(-(imageWidth * f - imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset); }// //下移// if (imageOffsetY > 0) {//  CGFloat totalOffset = imageHeight - ABS(imageOffsetY);//  CGFloat f = totalOffset / imageHeight;//  //  [self.headerImageView setFrame:CGRectMake(-(imageWidth * f - imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset)];// }}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end

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


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 午夜伦情电午夜伦情电影 | 毛片免费一区二区三区 | 久久久国产精品免费观看 | 中文字幕四区 | www.99tv| 日本高清视频网站www | 久色亚洲 | 99精品视频久久精品视频 | 黄色av.com| 49vv看片免费| 亚洲特黄 | 久久男人天堂 | 色综合欧美 | 中国毛片在线观看 | 特级毛片a级毛片100免费 | 爽爽视频免费看 | 在线亚洲欧美 | 毛片福利 | 操网 | 精品亚洲网站 | 免费观看又色又爽又黄的崩锅 | 一级毛片特黄 | 91福利免费观看 | 91成人免费网站 | 色妇视频 | 成人一级在线 | 免费看搡女人无遮挡的视频 | 久草在线播放视频 | 亚洲第一成人在线观看 | 成人在线视频免费播放 | 国产乱淫av | 国产精品视频亚洲 | 午夜爽爽爽男女免费观看hd | 久久吊| 亚洲国产高清视频 | 午夜久久电影 | 国产88久久久国产精品免费二区 | 久久精品99北条麻妃 | 黄色成人在线播放 | 亚洲视频精品在线 | 成人免费一区二区三区在线观看 |