UIWebview 和 powerpoint 分隔符问题
理想情况下,我想将我的 ppt 和 pdf 文档加载到没有边框或分隔符的 web 视图中。我不相信这是可能的。所以这个问题解决了如何优雅地处理 ppt 文档中的分隔线。
我正在尝试滚动浏览 ppt 进行自己的分页。我已经使用 webview 的滚动视图的内置分页尝试过此操作,但这不起作用。计算分隔线高度很困难,并且使用这种方法分隔线将始终存在。
目前我正在测试 31 页的幻灯片。有时,某些分隔线会显示在网络视图的顶部。 (第 15、24、25 和 26 页)
pptx 的宽高比为 16x9。我的网页视图是 1024x576,我假设这是网页视图中幻灯片的大小。
我计算分隔线尺寸如下。
文档加载时的高度为18069。
18069/576 ~ 31.369 这意味着有 31 页。
我计算分隔线占用的空间量如下:18069-(31*576) = 213。
那么 213/30 = 7.1 就是分隔线高度。
我对分隔线高度是小数感到非常困惑。此外,我很困惑为什么在 31 页的示例中,第 15、24、25、26 页没有正确排列。
抱歉,到目前为止似乎是针对特定大小的问题,但这是我的代码,用于处理动态大小文档的向下翻页操作。
- (void)handlePptSwipeUp:(UISwipeGestureRecognizer *)sender
{
//swipe up means scroll down
CGSize pptSize = pptWebView.scrollView.contentSize;
float y = pptSize.height;
int pages = y/pptWebView.frame.size.height;
float diff = pptSize.height - pages*pptWebView.frame.size.height;
float divider = diff/(pages-1);
CGPoint cOffset = pptWebView.scrollView.contentOffset;
float temp = pptScrollOffset + pptWebView.frame.size.height+divider;
if (temp+pptWebView.frame.size.height <= pptWebView.scrollView.contentSize.height) {
pptScrollOffset = temp;
}
CGRect visibleRect = CGRectMake(cOffset.x, pptScrollOffset, pptWebView.frame.size.width, pptWebView.frame.size.height);
[pptWebView.scrollView scrollRectToVisible:visibleRect animated:YES];
NSLog(@"content width %f\ncontent height %f\npages %d\ndiff %f\ndivider %f\npptScrollOffset %f",pptWebView.scrollView.contentSize.width,y,pages,diff,divider,pptScrollOffset);
}
这是滚动一页后的输出示例
content width 1024.000000
content height 18069.000000
pages 31
diff 213.000000
divider 7.100000
pptScrollOffset 583.099976
Ideally I would like to load my ppt and pdf documents into a webview without borders or dividers. I don't believe this is possible. So this question addresses handling the divider in a ppt document gracefully.
I am attempting to scroll through a ppt making my own paging. I have tried this using the built in paging of the webview's scrollview, but that didn't work. It is difficult to calculate the divider height and the divider will always be present using this approach.
Currently I am testing with a 31 page slideshow. Occasionally some of the divider shows on the top of the webview. (On the 15th, 24th, 25th, and 26th page)
The pptx has aspect ratio 16x9. My webview is 1024x576 and I am assuming that is the size of a slide within the webview.
I calculate the divider size as follows.
The height of the document when loaded is 18069.
18069/576 ~ 31.369 This means there are 31 pages.
I calculate the amount of space taken up by dividers as follows: 18069-(31*576) = 213.
Then 213/30 = 7.1 is the divider height.
I am very confused as to the divider height being a decimal. Further, I am confused as to why in the 31 page example, that pages 15,24,25,26 are the ones that don't line up properly.
Sorry for what seemed like a question directed at a specific size thus far, but here is my code to handle the page down action for dynamically sized documents.
- (void)handlePptSwipeUp:(UISwipeGestureRecognizer *)sender
{
//swipe up means scroll down
CGSize pptSize = pptWebView.scrollView.contentSize;
float y = pptSize.height;
int pages = y/pptWebView.frame.size.height;
float diff = pptSize.height - pages*pptWebView.frame.size.height;
float divider = diff/(pages-1);
CGPoint cOffset = pptWebView.scrollView.contentOffset;
float temp = pptScrollOffset + pptWebView.frame.size.height+divider;
if (temp+pptWebView.frame.size.height <= pptWebView.scrollView.contentSize.height) {
pptScrollOffset = temp;
}
CGRect visibleRect = CGRectMake(cOffset.x, pptScrollOffset, pptWebView.frame.size.width, pptWebView.frame.size.height);
[pptWebView.scrollView scrollRectToVisible:visibleRect animated:YES];
NSLog(@"content width %f\ncontent height %f\npages %d\ndiff %f\ndivider %f\npptScrollOffset %f",pptWebView.scrollView.contentSize.width,y,pages,diff,divider,pptScrollOffset);
}
Here is an example of the output after scrolling one page
content width 1024.000000
content height 18069.000000
pages 31
diff 213.000000
divider 7.100000
pptScrollOffset 583.099976
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在另一页上读到类似的内容。
我现在找不到页面了...所以,我只是把可以获取幻灯片大小的代码放进去。
这是代码:
然后滚动 webView
该示例没有计算边框。只要把它们放进去,我想就完美了~~
I read a similar thing on other page.
I can't find the page now...so, I just put the code that can get the size of the slide.
This is the code:
Then scroll the webView
This sample didn't count the borders. Just put them in, I think it will be perfect~~