我正在尝试滚动到在 webView 中查看的 PDF 的上次查看位置。 PDF卸载时,会保存webView的scrollView的y偏移量。然后当 PDF 重新打开时,我想跳到他们离开的地方。
下面的代码在 animated 设置为 YES 时工作正常,但是当它设置为 NO 时,什么也没有发生
float scrollPos = [[settingsData objectForKey:kSettingsScrollPosition]floatValue];
NSLog(@"scrolling to %f",scrollPos);
[webView.scrollView setContentOffset:CGPointMake(0, scrollPos) animated:NO];
NSLog(@"ContentOffset:%@",NSStringFromCGPoint(webView.scrollView.contentOffset));
这个输出:
滚动到 5432.000000
CO:{0, 5432}
但是PDF仍然显示首页
我在这里查看了类似问题的答案,但他们没有解决这个问题。
感谢您的帮助:)
最佳答案
在 UIWebView 组件完成 PDF 渲染之前,您不能触摸 contentOffset。它适用于 setContentOffset: animated:YES 因为动画会强制渲染。
如果在渲染开始后将contentOffset设置为至少0.3s(根据我的测试),则完全没有问题。
例如,如果您在 UIViewController 的 viewDidLoad 中加载 PDF,您可以在 中使用 延迟performSelector:withObject:afterDelay: >viewDidAppear:contentOffset设置。
要在设置 contentOffset 之前隐藏 PDF,您可以将其 alpha 设置为 0.01(不要将其设置为 0,除非渲染不会开始)并在设置后将其设置回 1 contentOffset。
@interface ViewController : UIViewController
{
UIWebView *w;
}
@property (nonatomic, retain) IBOutlet UIWebView *w;
@end
@implementation ViewController
@synthesize w;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *u = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf"];
[w loadRequest:[NSURLRequest requestWithURL:u]];
w.alpha = 0.01f;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:@selector(adjust) withObject:nil afterDelay:0.5f];
}
- (void)adjust
{
float scrollPos = 800;
NSLog(@"scrolling to %f",scrollPos);
[w.scrollView setContentOffset:CGPointMake(0, scrollPos) animated:NO];
NSLog(@"ContentOffset:%@", NSStringFromCGPoint(w.scrollView.contentOffset));
w.alpha = 1;
}
@end
关于ios - setContentOffset : animated: wont do anything if animated = NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730815/
这里有一个很好的答案解释了如何在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”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
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上
我有这个代码:context"Visitingtheusers#indexpage."dobefore(:each){visitusers_path}subject{page}pending('iii'){shouldhave_no_css('table#users')}pending{shouldhavecontent('Youhavereachedthispageduetoapermissionic错误')}它会导致几个待处理,例如ManagingUsersGivenapractitionerloggedin.Visitingtheusers#indexpage.#Noreason
在尝试实现应用auto_orient的过程之后!对于我的图片,我收到此错误:ArgumentError(noimagesinthisimagelist):app/uploaders/image_uploader.rb:36:in`fix_exif_rotation'app/controllers/posts_controller.rb:12:in`create'Carrierwave在没有进程的情况下工作正常,但在添加进程后尝试上传图像时抛出错误。流程如下:process:fix_exif_rotationdeffix_exif_rotationmanipulate!do|image|
我在Backtrack5中使用Ruby1.9.2dev编写脚本,但在尝试使用库“htmlentities”解析html实体时遇到了一些问题。虽然我已经用gem安装了它,但我无法加载它。我将向您展示我在控制台中遇到的问题:root@bt:~#gemlist-dhtmlentities***LOCALGEMS***htmlentities(4.3.1)Author:PaulBattleyHomepage:https://github.com/threedaymonk/htmlentitiesInstalledat:/var/lib/gems/1.9.2Amoduleforencodinga
我用这个错误搜索了jekyll。jekyll处理页面时似乎出现了ruby错误,但我根本不了解ruby。杰基尔版本1.3.1我什至重新安装了ruby和jekyll,但结果没有改变。更新:在我将jekyll从1.31降级到1.20后,这个错误消失了注意:我的网站是用jekyll1.20创建的,所以它不能用1.3.1构建?这是核心问题吗?E:\GitHub\sample>jekyll服务--trace:Configurationfile:E:/GitHub/sample/_config.ymlSource:E:/GitHub/sampleDestination:E:/GitHub
当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#
当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab