ios - 在 UITableView 中滚动时缩放图像
<p><p>我正在尝试重现这种效果 -</p>
<p>在 UITableView 的 header 部分中有一个 UIImageView。当用户向下滚动时,图像的大小会减小并在导航栏下方滚动,而当用户向上滚动时,UIImageView 会展开并返回到其原始位置。 </p>
<p>iOS 版 Twitter 会对你的个人资料产生这种影响。</p>
<p>到目前为止,这就是我所知道的 - 代码将位于 scrollViewDidScroll 方法下,我将不得不使用 2 张图像,一张大一张小。我需要帮助弄清楚如何在方法内的这两个图像之间进行转换。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果你想实现 Twitter 滚动扩展 UIImageView,Yari D'areglia 的教程概述了如何做到这一点。你可能会发现它很有用。该链接包含一个演示所需效果的视频。 </p>
<p> <a href="http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/" rel="noreferrer noopener nofollow">http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/</a> </p>
<p> <a href="https://github.com/michaelhenry/MHYahooParallaxView" rel="noreferrer noopener nofollow"><strong>Alternative Source Code</strong></a> </p>
<pre><code>#define IMAGE_VIEW_TAG 100
#define IMAGE_SCROLL_VIEW_TAG 101
#pragma mark - ScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView.tag == IMAGE_SCROLL_VIEW_TAG) return;
UITableView * tv = (UITableView*) scrollView;
UITableViewCell * cell = ];
UIScrollView * svImage = (UIScrollView*);
CGRect frame = svImage.frame;
frame.size.height =MAX((_imageHeaderHeight-tv.contentOffset.y),0);
frame.origin.y = tv.contentOffset.y;
svImage.frame = frame;
svImage.zoomScale = 1 + (abs(MIN(tv.contentOffset.y,0))/320.0f);
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell;
NSLog(@"Row %@", indexPath);
if(indexPath.row == 0){
static NSString * headerId = @"headerCell";
cell = ;
if(!cell) {
// create cell as it doesn't exist
cell = [initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, _imageHeaderHeight)];
cell.backgroundColor = ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// image view
UIImageView * imageView = [initWithFrame:CGRectMake(0.0f, 0.0f, cell.contentView.frame.size.width, _imageHeaderHeight)];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.tag = IMAGE_VIEW_TAG;
imageView.clipsToBounds = YES;
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
UIScrollView * svImage = [initWithFrame:imageView.frame];
svImage.delegate = self;
svImage.userInteractionEnabled = NO;
;
// image
svImage.tag = IMAGE_SCROLL_VIEW_TAG;
svImage.backgroundColor = ;
svImage.zoomScale = 1.0f;
svImage.minimumZoomScale = 1.0f;
svImage.maximumZoomScale = 2.0f;
;
UIImageView * headerInfo = [ initWithImage:];
;
CGRect headerFrame = headerInfo.frame;
headerFrame.size.height = 149.0f;
headerFrame.origin.y = _imageHeaderHeight - 149.0f;
headerInfo.frame = headerFrame;
}
// cell exists - grab a reference to the image it displays
UIImageView *imageView = (UIImageView*);
// maybe change the imageView
return cell;
}
</code></pre>
<ul>
<li>取自迈克尔·亨利:<a href="https://github.com/michaelhenry/MHYahooParallaxView" rel="noreferrer noopener nofollow">https://github.com/michaelhenry/MHYahooParallaxView</a> </li>
</ul></p>
<p style="font-size: 20px;">关于ios - 在 UITableView 中滚动时缩放图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27530891/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27530891/
</a>
</p>
页:
[1]