UIWebview 滑动到另一个 UIWebview

发布于 2024-07-30 04:19:49 字数 223 浏览 6 评论 0原文

这里完全是菜鸟。 我想弄清楚如何实现 通过滑动从一个 UIWebview 过渡到另一个 UIWebview,并且仍然能够在每个 Webview 中滚动/缩放。

每个 Web 视图都应该正常响应所有触摸/手势,除非检测到滑动并且视图/内容的边界位于屏幕的相应边缘(如分页滚动视图)。

我的内容是来自数据对象的 html 字符串。

任何提示将不胜感激。 谢谢。

Total nooob here. I'm trying to figure out how to implement a
transition from one UIWebview to another with a swipe and still be able to scroll/zoom w/in each webview.

Each webview should respond normally to all touches/gestures unless a swipe is detected and the boundry of the view/content is at the corresponding edge of the screen (like a paging scroll view).

My content is an html string from a data object.

Any tips would be appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那小子欠揍 2024-08-06 04:19:49

看起来将 UIWebview 放入 UIScrollview 在 iPhone 3.0 中效果很好 - 'Doh!!!

Looks like putting a UIWebview in a UIScrollview works fine in iPhone 3.0 - 'Doh!!!

老旧海报 2024-08-06 04:19:49

将 UIWebView 放入 ScrollView 中可能是有原因的,但在 UIWebView 中支持滑动和滚动并不是其中之一。 UIWebView 本身可以很好地处理页面上的滚动,并且拥有它的视图控制器可以支持滑动以更改为其他控制器,例如通过执行以下操作:

1)在拥有 WebView 的 viewController 中实现 UIGestureRecognizerDelegate 方法:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gr shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGr
{
    return YES;
}

这允许您在 webViewController 中实现的手势识别器还可以从 UIWebView 获取手势。 否则 UIWebView 会消耗所有这些并且不会将它们传递给您。

2) 区分页面上的滑动和滚动。 在添加到 UIWebView 的实际手势识别器上,将称为“滑动”所需的触摸次数设置为 2 或 3 之类的值。这允许一根手指在页面上滚动,并且仅在 2 或 3 个手指时返回 SwipeGesture被使用。 这样做:

 UISwipeGestureRecognizer *swipeGR;
 swipeGR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft)] autorelease];
 swipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
 swipeGR.delegate = self;
 swipeGR.numberOfTouchesRequired = 2;
 [myWebView addGestureRecognizer:swipeGR];

There may be reasons to put a UIWebView in a ScrollView, but supporting BOTH swipe and scrolling in UIWebView is not one of them. The UIWebView handles scrolling around on the page just fine by itself, and the view controller that owns it can support swipe to change to something else like another controller by doing the following:

1) In the viewController which owns the WebView implement the UIGestureRecognizerDelegate method:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gr shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGr
{
    return YES;
}

This allows the gesture recognizer you implement in your webViewController to ALSO get gestures from the UIWebView. Else the UIWebView consumes all of them and will not pass them on to you.

2) To make a distinction between a Swipes and scrolling around on a page. On the actual gesture recognizer you are adding to the UIWebView set the number of touches required to be called a "Swipe" to something like 2 or 3. This allows one finger scrolling on a page and will only return a SwipeGesture when 2 or 3 fingers are used. Do it something like this:

 UISwipeGestureRecognizer *swipeGR;
 swipeGR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft)] autorelease];
 swipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
 swipeGR.delegate = self;
 swipeGR.numberOfTouchesRequired = 2;
 [myWebView addGestureRecognizer:swipeGR];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文