iOSios开发iOS Developer

iOS tableView视图下拉拉伸效果

2015-12-31  本文已影响3227人  JustFavor

、、、

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

@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应该是同比例缩放。

}

}

、、、

上一篇 下一篇

猜你喜欢

热点阅读