2014-11-03 2 views
2

터치가 webview 외부에서 끝나면 "onTouchEnd"는 실행되지 않습니다. 컴파일은 엑스 코드 6, iOS 용 8, 아이폰 6IOS - 전체 화면이 아닌 webview에 대한 "touchend"이벤트 없음

와 나는 다음의 레이아웃을 가지고 : 나는 웹보기의 모든 터치 이벤트, 터치 시작 및 종료를받을 수 있습니다

|Navigation TAB| 
|Left view|Web view|Right view| 
|page view| 

. 그러나 웹 뷰에서 터치를 시작한 다음 터치를 외부로 이동하면 webview 테두리를 떠나 자마자 touchmove 이벤트 수신을 중단하고 touchend 이벤트가 수신되지 않습니다.

코드 FOT 테스트 HTML 파일 :이 해결 될 수있는 방법 "의 viewDidLoad"기능

[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

self.webView = [[UIWebView alloc] initWithFrame:self.mainView.bounds]; 

[self.webView setScalesPageToFit:YES]; 
[self.webView setAlpha:1]; 

/* Disable scrolling of web view */ 
for (id subview in [self.webView subviews]) { 
    if ([subview isKindOfClass:[UIScrollView class]]) { 
     ((UIScrollView*)subview).bounces = NO; 
    } 
} 

self.webView.scrollView.bounces = NO; 
self.webView.scrollView.canCancelContentTouches = NO; 
self.webView.scrollView.scrollEnabled = NO; 

self.webView.backgroundColor = [UIColor magentaColor]; //[UIColor colorWithRed:(45.0/255.0) green:(50.0/255.0) blue:(53.0/255.0) alpha:1]; 
self.webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
[self.mainView addSubview:self.webView]; 


NSString * localHtmlFilePath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"html" inDirectory:@"www"]; 
NSString *html = [NSString stringWithContentsOfFile:localHtmlFilePath encoding:NSUTF8StringEncoding error:nil]; 



[self.webView loadHTMLString:html baseURL:nil]; 

<head> 
    </head> 
    <body bgcolor="#CC6" 
     ontouchmove="console.info('move');" 
     ontouchstart="console.info('start');" 
     ontouchend="console.info('end');" 
     ontouchcancelled="console.info('canceled');" 
    > 
    <h1>This is a test</h1> 
    <p> Lore ip sum </p> 
    </body> 

코드? 내가 놓친 구성이 있습니까?

완전한 소스 코드는 여기에서 찾을 수 있습니다 : https://github.com/Daraku/WebViewBug

답변

2

나는 결국 내가 모든 touchmove 복원지고 타임 아웃을 구현하기로 결정했고 touchstart에서 시작, 지난 삼십분에 대해 동일로 strugling 된 touchend에 삭제됩니다. 타임 아웃은 1500ms라고 말하고, 내가해야할 것처럼 webview에서 touchend을 해지시키지 않으면 타임 아웃이 끝날 때 해고합니다.

희망이 있습니다. 완벽하지는 않지만 부분적인 수정으로 작용합니다. 내 경우에는 iScroll에 대한 해킹 (_execEvent ('scrollCancel'))

+1

에서는 setTimeout이 - 해킹, 내가 최종 무슨 일이 (내가 훨씬 작은 시간 값을 사용하지만)를 사용합니다. 보이는 것처럼, 적절한 해결책이 없습니다 : ( –

0

네이티브 앱에 webview를 삽입 한 것과 비슷한 문제가있었습니다. 네이티브 앱에는 60px 크기의 헤더가 있고 그 아래에는 webview가 있습니다.

webview에서 위로 스 와이프하고 손가락으로 손가락을 떼면 'touchend'이벤트가 webview로 전달되지 않습니다.

'touchmove'이벤트의 Y 좌표가 맨 위에 webview를 떠날 때 음수라는 것을 알았 기 때문에이 사실을 듣고 touchend 이벤트를 프로그래밍 방식으로 트리거함으로써 그 사실을 활용했습니다. 직장 상사처럼!

document.addEventListener("touchmove", function(e) { 
if (e.changedTouches[0].pageY < 0) { 
    e.preventDefault(); 
    document.dispatchEvent(new Event('touchend')); 
} 

}, false);

다음은 동일한 코드의 요지입니다 : https://gist.github.com/EddyVerbruggen/70b96fce47fa7bf7a34f03e3a2ecb85f

+0

불행히도, 손가락이 물리적 화면이 아닌 WebView 영역을 떠날 때 나는 그것을 잡아야합니다. –

관련 문제