适用于iOS的Tweetbot和Kickstarter在具有横幅图像的用户配置文件上使用了很酷的功能.如果您向下拉桌子,则图像会缩放.
我使用以下部分工作,它改变了图像的高度,但奇怪的是,不是宽度:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { UIImageView *imageView = (UIImageView *)self.tableView.tableHeaderView; CGFloat y = -scrollView.contentOffset.y; imageView.frame = CGRectMake(0,scrollView.contentOffset.y,self.cachedImageViewSize.size.width+y,self.cachedImageViewSize.size.height+y); NSLog(@"%@",NSStringFromCGRect(imageView.frame)); }
有谁知道如何重现这种效果?
解决方法
好的,我明白了.这是我做的:
- (void)viewDidLoad { [super viewDidLoad]; self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"church-welcome.png"]]; self.imageView.contentMode = UIViewContentModeScaleAspectFill; self.cachedImageViewSize = self.imageView.frame; [self.tableView addSubview:self.imageView]; [self.tableView sendSubviewToBack:self.imageView]; self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.width,170)]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat y = -scrollView.contentOffset.y; if (y > 0) { self.imageView.frame = CGRectMake(0,self.cachedImageViewSize.size.height+y); self.imageView.center = CGPointMake(self.view.center.x,self.imageView.center.y); } }