您的位置:首页 > 移动开发

UIWebView about some properties

2011-06-27 21:53 393 查看
1.  How to disable the webview could scroll.

    [(UIScrollView *)[[_webView subviews] objectAtIndex:0] setBounces:NO];

2.  Get the html title for webview content.

    Using JavaScript:

    NSString *htmlTitle = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];

3.  Support the UITouch Event.

    Using JavaScript:

    #define WebTouchJavaScript @"<script language="javascript">document.ontouchstart=function(){document.location="myweb:touch:start";}; document.ontouchend=function(){document.location="myweb:touch:end";};document.ontouchmove=function(){document.location="myweb:touch:move";}</script>"

    the webview will load the html string, using this java script between the <body> and </body>.
Then, method: [_webView loadHTMLString: baseURL: ] to load. And then the web view could support the UITouch event.

    The delegaete method to judge which touch event is occur.

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request   
                                       navigationType:(UIWebViewNavigationType)navigationType {   
   
    NSString *requestString = [[request URL] absoluteString];
    NSArray *components = [requestString componentsSeparatedByString:@":"];
    if ([components count] > 1 &&
        [(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
             if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"]) {
             //Dispatch the UITouch Event and handle with reference actions.
             NSLog(@"touch : %@", [components objectAtIndex:2]);

4,禁止选中文本
  [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息