iOS tableView视图下拉拉伸效果

、、、

//在延展中声明一个属性

@property (nonatomic, strong) UIImageView *headerImageView;

// viewDidLoad里面不需要要写太多东西,像一般的UI 布局最好拿出来封装在外部,这个里面的内容经量简洁明了。

- (void)viewDidLoad {

[super viewDidLoad];

[self layoutHeaderImageView];

}

// 配置tableView header UI布局

- (void)layoutHeaderImageView {

UIView *headerView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];

self.headerImageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, self.view.frame.size.width, 200))];

self.headerImageView.image  = [UIImage imageNamed:@"1414714589213179.jpg"]; // 自己选择的图片

[headerView addSubview:self.headerImageView];

self.tableView.tableHeaderView = headerView;

}

// 下拉后图片拉伸的效果方法下载这个里面

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat width = self.view.frame.size.width; // 图片宽度

CGFloat yOffset = scrollView.contentOffset.y;  // 偏移的y值

if (yOffset < 0) {

CGFloat totalOffset = 200 + ABS(yOffset);

CGFloat f = totalOffset / 200;

self.headerImageView.frame =  CGRectMake(- (width * f - width) / 2, yOffset, width * f, totalOffset); //拉伸后的图片的frame应该是同比例缩放。

}

}

、、、

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容