适用于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); } }
原文地址:https://www.jb51.cc/iOS/333481.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。