I've tried the following:
我尝试过以下方法:
html, body, div, p, a, table, img
{
-webkit-user-select: none !important;
user-select: none !important;
-webkit-user-callout: none !important;
-webkit-touch-callout: none !important;
}
This works for my uiwebview that takes up the whole screen, but for my uiwebview that does not (adbannerview above), it pushes the magnifying glass above the uiwebview over the adbannerview.
这适用于占据整个屏幕的uiwebview,但对于我没有的uiwebview(上面的adbannerview),它将uiwebview上方的放大镜推到了adbannerview上。
Does anyone have any ideas that don't involve disabling UILongPressGestureRecognizers
on uiwebview's subviews as suggested in this answer?
有没有任何想法不涉及在uiwebview的子视图中禁用UILongPressGestureRecognizers,如本答案所示?
2 个解决方案
#1
6
I managed to get suggested comments working by ensuring gestures are disabled after each page load.
我设法通过确保在每次加载页面后禁用手势来获得建议的评论。
So, in your webview delegate:
所以,在你的webview委托中:
func webViewDidFinishLoad(webView: UIWebView) {
disableLongPressGesturesForView(webView)
}
Then your function can look up each subview of the webview (and it's subview children), and disable any long press gestures.
然后,您的函数可以查找webview的每个子视图(以及它的子视图子项),并禁用任何长按手势。
func disableLongPressGesturesForView(view: UIView) {
for subview in view.subviews {
if let gestures = subview.gestureRecognizers as [UIGestureRecognizer]! {
for gesture in gestures {
if gesture is UILongPressGestureRecognizer {
gesture.enabled = false
}
}
}
disableLongPressGesturesForView(subview)
}
}
#2
2
I disabled the magnifying glass by iterating the subviews from the webview and finding which has UILongPressGestureRegonizer then disable it
我通过迭代webview中的子视图并找到哪个具有UILongPressGestureRegonizer然后禁用它来禁用放大镜
Here is the snippet :
这是片段:
- (void)disableWebViewLongPressGestures:(UIWebView *)webview {
for(id subView in webview.subviews) {
if([subView isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subView;
for(id ssView in scrollView.subviews) {
if([NSStringFromClass([ssView class]) isEqualToString:@"UIWebBrowserView"]) {
for(UIGestureRecognizer *gs in [ssView gestureRecognizers]) {
if ([gs isKindOfClass:[UILongPressGestureRecognizer class]])
{
gs.enabled = NO;
}
}
}
}
}
}
}
#1
6
I managed to get suggested comments working by ensuring gestures are disabled after each page load.
我设法通过确保在每次加载页面后禁用手势来获得建议的评论。
So, in your webview delegate:
所以,在你的webview委托中:
func webViewDidFinishLoad(webView: UIWebView) {
disableLongPressGesturesForView(webView)
}
Then your function can look up each subview of the webview (and it's subview children), and disable any long press gestures.
然后,您的函数可以查找webview的每个子视图(以及它的子视图子项),并禁用任何长按手势。
func disableLongPressGesturesForView(view: UIView) {
for subview in view.subviews {
if let gestures = subview.gestureRecognizers as [UIGestureRecognizer]! {
for gesture in gestures {
if gesture is UILongPressGestureRecognizer {
gesture.enabled = false
}
}
}
disableLongPressGesturesForView(subview)
}
}
#2
2
I disabled the magnifying glass by iterating the subviews from the webview and finding which has UILongPressGestureRegonizer then disable it
我通过迭代webview中的子视图并找到哪个具有UILongPressGestureRegonizer然后禁用它来禁用放大镜
Here is the snippet :
这是片段:
- (void)disableWebViewLongPressGestures:(UIWebView *)webview {
for(id subView in webview.subviews) {
if([subView isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView *)subView;
for(id ssView in scrollView.subviews) {
if([NSStringFromClass([ssView class]) isEqualToString:@"UIWebBrowserView"]) {
for(UIGestureRecognizer *gs in [ssView gestureRecognizers]) {
if ([gs isKindOfClass:[UILongPressGestureRecognizer class]])
{
gs.enabled = NO;
}
}
}
}
}
}
}