在ios9的uiwebview中显示pdf有时会卡住 [英] showing a pdf in uiwebview on ios9 sometimes scrolling is stuck

查看:98
本文介绍了在ios9的uiwebview中显示pdf有时会卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用Swift xcode7编写的ios应用

I'm working on an ios app written in swift, xcode7

视图上有一个UIWebView.

使用loadRequest(NSURLRequest)我们从磁盘加载pdf文件. 这可以正常工作,但有时pdf文件无法滚动到第一页或您在屏幕上首先看到的内容.我无法查明是什么原因导致无法滚动,因为有时我会再次打开同一文件,然后滚动.

using loadRequest(NSURLRequest) we load a pdf file from disk. This works fine, but sometimes the pdf file cannot be scrolled past the first page or what you see first on the screen. I can't pinpoint what causes the not-scrolling as sometimes I open the same file again and then it scrolls.

在不想跳到屏幕底部时尝试滚动,可以看到还有另一页,但是您无法将其滚动到视图中.

Trying to scroll when it doesn't want to bounces the bottom part of the screen and you can see there is another page, but you can't scroll it into view.

UIWebView中包含的UIScrollView(这是默认设置)知道还有更多的页面,因为它在屏幕上显示"3之1".

The UIScrollView contained inside the UIWebView (this is the default) knows there are more pages, because it shows "1 of 3" on screen.

UIWebView

  • 已选中缩放页面以适合"
  • 已选中启用用户互动"
  • 未选中多点触摸"
  • 已选中自动调整子视图"
  • 具有缩放至填充"模式

我尝试了以下操作:

  • 通过在滚动视图周围放置边框来检查滚动视图是否不大于屏幕:不,它适合屏幕并且大小与您期望的一样
  • 在代码中将内部UIScrollView.scollEnabled设置为true
  • checking if the scrollview is not larger than the screen by placing a border around it: no, it fits on screen and is as large as you would expect
  • setting the internal UIScrollView.scollEnabled to true in code

在应用程序中,当显示UIWebview时,它会通过折叠上方的元素在屏幕上调整大小,但是我已经以固定的高度对其进行了测试,并且它没有任何改变.

In the application, when showing the UIWebview, it is resized on screen by collapsing an element above it, but I have tested this with fixed heights and it doesn't change anything.

当我在内部UIScrollView上调用flashScrollIndicators()时,这与滚动或非滚动一致.如果看到滚动条闪烁,则可以滚动.如果没有,则无法滚动到第一页.

When I call flashScrollIndicators() on the internal UIScrollView, this is consistent with the scrolling or non-scrolling. If you see the scrollbar flash, then scrolling is possible. If not, then you can't scroll past the first page.

还有其他可以尝试的想法吗?

Any other ideas I can try?

推荐答案

潜在的问题是,在加载新的pdf之前,每次都通过加载'about:blank'来清除UIWebView,这是建议的解决方案清除网页视图.但是,当使用具有不同页面大小和不同页面数的pdf时,这似乎与内置的scrollview混为一谈.

The underlying problem was the fact that before loading a new pdf, the UIWebView was cleared each time by loading 'about:blank', which is the most suggested solution to clear the webview. However, when working with pdfs with different page sizes and different number of pages, this seems to mess with the built-in scrollview.

在这种情况下,解决方案是创建一种具有单个页面的空白" pdf文件(可能在其中包含应用程序徽标,以便于用户清楚地区分),而不是加载about:blank,而是加载此pdf文件在向用户显示Web视图之前,以及等待将实际pdf下载到设备上时.

The solution in this case was to create a kind of 'blank' pdf with a single page (and maybe an application logo in it to distinguish it clearly for the user) and instead of loading about:blank, load this pdf instead before showing the webview to the user and while waiting for the real pdf to download to the device.

这篇关于在ios9的uiwebview中显示pdf有时会卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆