简体   繁体   English

像Apple Mail.app一样的UIScrollView中的UIWebView

[英]UIWebView within a UIScrollView like the Apple Mail.app

I am trying to create a view similar to what you see when reading an email in the Apple iOS Mail.app, where you can pinch anywhere in the view to zoom the UIWebView in and out, and the header at the top stays the same size. 我正在尝试创建一个与在Apple iOS Mail.app中阅读电子邮件时看到的视图类似的视图,在该视图中您可以捏住视图中的任何位置以放大和缩小UIWebView,并且顶部的标题保持不变。

Also, scrolling up/down should scroll the entire view, not just the UIWebView. 另外,向上/向下滚动应该滚动整个视图,而不仅仅是UIWebView。 Scrolling left and right only scrolls the UIWebView left/right, it does not affect the header. 左右滚动仅可左右滚动UIWebView,不会影响标题。

I've already tried using a UITableView with the UIWebView as a view within a cell or as a header/footer view, but I could not the scrolling and zooming do not work correctly. 我已经尝试过将UITableView和UIWebView用作单元格中的视图或页眉/页脚视图,但是无法正常滚动和缩放。

I am now trying to put a UIWebView within a UIScrollView and can't seem to get the scrolling to work correctly this way either, but it seems to be a better approach than putting the UIWebView in a UITableViewCell. 我现在正在尝试将UIWebView放在UIScrollView中,并且似乎也无法使滚动以这种方式正常工作,但这似乎比将UIWebView放入UITableViewCell中更好。

Here is a simple representation of the view hierarchy I am trying to create: 这是我要创建的视图层次结构的简单表示:

UIScrollView
-- UIView (this is the "header" view)
-- UIWebView

I am not sure if I need to disable scrolling/zooming on the UIWebView, or how to handle the scroll events for the container UIScrollView or the UIWebView internal scrollview. 我不确定是否需要禁用UIWebView上的滚动/缩放或如何处理容器UIScrollView或UIWebView内部scrollview的滚动事件。

Thanks in advance for any examples and advice! 在此先感谢您提供任何示例和建议! Please let me know if I left out any details. 如果我遗漏了任何细节,请告诉我。

As long as you know that a web view contains a scroll view then you are fine but I would suggest the following and it worked for me once: 只要您知道Web视图包含滚动视图,就可以了,但是我建议以下内容,并且对我有用一次:

Add a UIView between the scroll view and the other elements inside it (including the web view) and let iOS handles the rest of the stuff (gestures and scrolling events) 在滚动视图和其中的其他元素(包括Web视图)之间添加UIView,并让iOS处理其余内容(手势和滚动事件)

UIScrollView
-- UIView (Just a wrapper as big as the content of the scroll view)
   -- UIView (this is the "header" view)
   -- UIWebView

I don't know if you already found a solution for your problem but I was facing the same and I wanted to share my solution. 我不知道您是否已经找到解决问题的方法,但是我也面临同样的问题,我想分享我的解决方案。

I implemented a custom UIWebView with the same behavior as the native mail app. 我实现了一个自定义UIWebView ,其行为与本机邮件应用程序相同。 Maybe it will save someone some valuable time :) I know I wish there was such a thing when I was struggling. 也许它将为某人节省一些宝贵的时间:)我知道我希望自己在挣扎中有这样的事情。

This is the link to the project: https://github.com/catalinaturlea/HeaderWebView 这是项目的链接: https : //github.com/catalinaturlea/HeaderWebView

If you find any problems or think about any improvements, please let me know. 如果您发现任何问题或有任何改进的想法,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM