资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么在iOS中使用tableView实现顶部图片拉伸效果-创新互联

本篇文章为大家展示了怎么在iOS中使用tableView实现顶部图片拉伸效果,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

成都创新互联专注于企业全网整合营销推广、网站重做改版、双流网站定制设计、自适应品牌网站建设、H5技术商城建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为双流等各大城市提供网站开发制作服务。
#define SCREEN_W [UIScreen mainScreen].bounds.size.width 
#define SCREEN_H [UIScreen mainScreen].bounds.size.height 
#define TOP 200 //顶部预留 
 
#import "ViewController.h" 
 
@interface ViewController () 
@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

上述内容就是怎么在iOS中使用tableView实现顶部图片拉伸效果,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联网站建设公司行业资讯频道。

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:怎么在iOS中使用tableView实现顶部图片拉伸效果-创新互联
文章位置:http://cdkjz.cn/article/dodpgs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220