自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)中如何使UIWebView響應(yīng)Touch事件

移動(dòng)開發(fā) iOS
iPhone開發(fā)中如何使UIWebView響應(yīng)Touch事件是本文要介紹的內(nèi)容,主要是來介紹如何使UIWebView響應(yīng)Touch事件,具體內(nèi)容來看本文詳解。

iPhone開發(fā)中如何使UIWebView響應(yīng)Touch事件是本文要介紹的內(nèi)容,主要是來介紹如何使UIWebView響應(yīng)Touch事件,具體內(nèi)容來看本文詳解。UIWebView響應(yīng)不了Touch事件,很久以前就很難解決。***有一個(gè)叫做UICWebView的東西,雖然用了private api,但是可以用。

不過UICWebView或者任何用UIWebDocumentView獲得事件的方法在iOS4 100%會(huì)出錯(cuò)(因?yàn)閁IWebDocumentView這個(gè)東西沒了)。用下面的方法可以讓UIWebView響應(yīng)Touch事件,而且不會(huì)影響滾動(dòng)拖拽的bouncing。

如果需要touch的個(gè)數(shù)或者坐標(biāo),也很簡單,不過需要自己修改代碼里的JavaScript。

  1. - (void)viewDidLoad {  
  2.     [super viewDidLoad];  
  3.     selfself.webView.delegate=self;  
  4.     NSString *resourcePath = [ [NSBundle mainBundle] resourcePath];  
  5.     NSString *filePath = [resourcePath stringByAppendingPathComponent:@"test.html"];  
  6.     NSString *htmlstring=[[NSString alloc] initWithContentsOfFile:filePath  encoding:NSUTF8StringEncoding error:nil];  
  7.     NSString *newHTMLString=[htmlstring stringByAppendingString:@"<script language=\"javascript\">
  8. document.ontouchstart=function(){          
  9. document.location=\"myweb:touch:start\";  }; 
  10. document.ontouchend=function(){         
  11.  document.location=\"myweb:touch:end\";  
  12. }; 
  13. document.ontouchmove=function(){        
  14.   document.location=\"myweb:touch:move\"; 
  15.  }  
  16. </script>"
  17. ];  
  18.     [self.webView loadHTMLString:newHTMLString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];  
  19.     [htmlstring release];  
  20. }  
  21. - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)
  22. request navigationType:(UIWebViewNavigationType)navigationType {  
  23.     NSString *requestString = [[request URL] absoluteString];  
  24.     NSArray *components = [requestString componentsSeparatedByString:@":"];  
  25.     if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {  
  26.         if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"])  
  27.         {  
  28.             NSLog(@"%@",[components objectAtIndex:2]);  
  29.         }  
  30.         return NO;  
  31.     }  
  32.     return YES;  

小結(jié):iPhone開發(fā)中如何使UIWebView響應(yīng)Touch事件的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-08-18 15:56:08

iPhone開發(fā)內(nèi)存

2013-05-21 09:54:39

Web前端

2011-07-07 15:45:45

iPhone SQLite 數(shù)據(jù)

2011-07-21 17:00:59

iPhone UIWebView Status Cod

2011-08-22 11:28:46

iPhone開發(fā)BMP

2011-08-22 10:49:42

Cocos2d 開發(fā)CCLayerTouch事件

2011-09-05 12:49:59

Sencha Touc事件

2011-07-26 09:58:24

2011-08-02 16:28:40

iPhone Web開發(fā) 事件

2013-04-15 15:22:06

2011-08-02 11:07:42

iOS開發(fā) UIWebView

2011-09-06 15:53:41

Qt平臺(tái)GUI

2011-07-22 13:23:56

IOS UI ScrollView

2013-04-24 11:15:56

Android開發(fā)Touch事件傳遞機(jī)制

2011-08-05 16:10:31

iPhone 網(wǎng)絡(luò) NSURLConne

2011-08-02 17:58:09

iPhone開發(fā) 事件

2011-08-17 15:10:21

iPhone開發(fā)Web視圖

2022-04-14 16:00:51

事件響應(yīng)流程企業(yè)

2021-02-01 16:55:13

iPhoneTouch ID蘋果

2011-08-03 17:32:17

IOS UIScrollVi touch
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)