我正在尝试重现这种效果 -
在 UITableView 的标题部分有一个 UIImageView。当用户向下滚动时,图像的大小会减小并滚动到导航栏下方,当用户向上滚动时,UIImageView 会展开并返回到其原始位置。
iOS 版 Twitter 对您的个人资料有这种影响。
到目前为止,这就是我所知道的 - 代码将在 scrollViewDidScroll 方法下,我将不得不使用 2 个图像,一大一小。我需要帮助弄清楚如何在方法内的这两个图像之间进行转换。
最佳答案
如果您想要实现 Twitter 滚动扩展 UIImageView,Yari D'areglia 的教程概述了如何做到这一点。您可能会发现它很有用。该链接包含演示所需效果的视频。
http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/
#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 = [tv cellForRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
UIScrollView * svImage = (UIScrollView*)[cell viewWithTag:IMAGE_SCROLL_VIEW_TAG];
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 [scrollView viewWithTag:IMAGE_VIEW_TAG];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell;
NSLog(@"Row %@", indexPath);
if(indexPath.row == 0){
static NSString * headerId = @"headerCell";
cell = [tableView dequeueReusableCellWithIdentifier:headerId];
if(!cell) {
// create cell as it doesn't exist
cell = [[UITableViewCell alloc]initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, _imageHeaderHeight)];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// image view
UIImageView * imageView = [[UIImageView alloc]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 = [[UIScrollView alloc]initWithFrame:imageView.frame];
svImage.delegate = self;
svImage.userInteractionEnabled = NO;
[svImage addSubview:imageView];
// image
svImage.tag = IMAGE_SCROLL_VIEW_TAG;
svImage.backgroundColor = [UIColor blackColor];
svImage.zoomScale = 1.0f;
svImage.minimumZoomScale = 1.0f;
svImage.maximumZoomScale = 2.0f;
[cell.contentView addSubview:svImage];
UIImageView * headerInfo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[cell.contentView addSubview:headerInfo];
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*)[cell viewWithTag:IMAGE_VIEW_TAG];
// maybe change the imageView
return cell;
}
关于ios - 在 UITableView 中滚动时缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27530891/
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path
2022/8/4更新支持加入水印水印必须包含透明图像,并且水印图像大小要等于原图像的大小pythonconvert_image_to_video.py-f30-mwatermark.pngim_dirout.mkv2022/6/21更新让命令行参数更加易用新的命令行使用方法pythonconvert_image_to_video.py-f30im_dirout.mkvFFMPEG命令行转换一组JPG图像到视频时,是将这组图像视为MJPG流。我需要转换一组PNG图像到视频,FFMPEG就不认了。pyav内置了ffmpeg库,不需要系统带有ffmpeg工具因此我使用ffmpeg的python包装p
有这样的事吗?我想在Ruby程序中使用它。 最佳答案 试试这个http://csl.sublevel3.org/jp2a/此外,Imagemagick可能还有一些东西 关于ruby-是否有将图像文件转换为ASCII艺术的命令行程序或库?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6510445/
我正在使用Dragonfly在Rails3.1应用程序上处理图像。我正在努力通过url将图像分配给模型。我有一个很好的表格:{:multipart=>true}do|f|%>RemovePicture?Dragonfly的文档指出:Dragonfly提供了一个直接从url分配的访问器:@album.cover_image_url='http://some.url/file.jpg'但是当我在控制台中尝试时:=>#ruby-1.9.2-p290>picture.image_url="http://i.imgur.com/QQiMz.jpg"=>"http://i.imgur.com/QQ
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
我对图像处理完全陌生。我对JPEG内部是什么以及它是如何工作一无所知。我想知道,是否可以在某处找到执行以下简单操作的ruby代码:打开jpeg文件。遍历每个像素并将其颜色设置为fx绿色。将结果写入另一个文件。我对如何使用ruby-vips库实现这一点特别感兴趣https://github.com/ender672/ruby-vips我的目标-学习如何使用ruby-vips执行基本的图像处理操作(Gamma校正、亮度、色调……)任何指向比“helloworld”更复杂的工作示例的链接——比如ruby-vips的github页面上的链接,我们将不胜感激!如果有ruby-