iOS——UITableVew 头部图片下拉放大
2015-07-09 14:59
573 查看
#import "MyViewController.h"
CGFloat const imageW=320;
CGFloat const imageH=320;
CGFloat const inseTop=150;
@interface MyViewController ()
@property (nonatomic ,strong)UIImageView *myimageView;
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.contentInset=UIEdgeInsetsMake(inseTop, 0, 0, 0);
self.myimageView=[[UIImageView alloc]init];
self.myimageView.image=[UIImage imageNamed:@"1436262350712853.jpg"];
self.myimageView.frame=CGRectMake(0, -inseTop, imageW, imageH);
//设置内容模式,也是核心代码
self.myimageView.contentMode=UIViewContentModeScaleAspectFill;
[self.tableView insertSubview:self.myimageView atIndex:0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 核心代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat dragdelta=-inseTop-scrollView.contentOffset.y;
if (dragdelta<0)
{
dragdelta=0;
}
CGRect new=self.myimageView.frame;
new.size.height=inseTop+dragdelta;
self.myimageView.frame=new;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID=@"id";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
NSString *title=[NSString stringWithFormat:@"哈哈:%ld",indexPath.row];
cell.textLabel.text=title;
return cell;
}
@end
CGFloat const imageW=320;
CGFloat const imageH=320;
CGFloat const inseTop=150;
@interface MyViewController ()
@property (nonatomic ,strong)UIImageView *myimageView;
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.contentInset=UIEdgeInsetsMake(inseTop, 0, 0, 0);
self.myimageView=[[UIImageView alloc]init];
self.myimageView.image=[UIImage imageNamed:@"1436262350712853.jpg"];
self.myimageView.frame=CGRectMake(0, -inseTop, imageW, imageH);
//设置内容模式,也是核心代码
self.myimageView.contentMode=UIViewContentModeScaleAspectFill;
[self.tableView insertSubview:self.myimageView atIndex:0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - 核心代码
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat dragdelta=-inseTop-scrollView.contentOffset.y;
if (dragdelta<0)
{
dragdelta=0;
}
CGRect new=self.myimageView.frame;
new.size.height=inseTop+dragdelta;
self.myimageView.frame=new;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ID=@"id";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
NSString *title=[NSString stringWithFormat:@"哈哈:%ld",indexPath.row];
cell.textLabel.text=title;
return cell;
}
@end
相关文章推荐
- iOS开发之剖析"秘密"App内容页面效果(二)
- 不一样的导航栏渐变
- 下拉放大图片
- 使用UICollectionView实现一个列表头部拉伸效果(下拉放大)(OC 和 Swift)
- 头部下拉放大(控件随着变化并透明)
- QZone下拉图片放大控件
- 【Android】商品详情页下拉放大动画工具类,一行代码集成使用
- Android下拉图片变大的ScrollView
- iOS开发-仿新浪博客个人主页效果
- iOS tableView下拉顶部视图放大 自动滚动 无限滚动 自动布局 在code4App和github上早就上传了代码,这边记录下
- 解决iOS11图片下拉放大出现信号栏白条的bug问题
- UIButton UIEdgeInsetsMake
- iOS笔记057 - UI总结03
- 1007. Maximum Subsequence Sum (25)
- Implement Queue using Stacks
- Android-优化UI性能(5)-优化布局文件
- [iOS]UIView动画学习笔记(下)
- Android-优化UI性能(4)-使用ViewStub
- UIViewController转场动画
- Codeforces Jzzhu and Sequences(圆形截面)