如何更改 UIWebView Tap 事件 [英] how to change UIWebView Tap events

查看:25
本文介绍了如何更改 UIWebView Tap 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 UIWebView tap 动作 Controls.like 当我 点击并按住 UIWebView 中的某个链接时代码> ..它打开一个带有三个选项的 UIActionSheet open copy add to reading list ...我需要要更改此 UIActionsheet 控件,例如 ..我需要再添加一个按钮到此...如何执行...如何禁用此功能并添加新的 UIActionSheet我的选择...

How Can I change the UIWebView tap action Controls.like when I tap and hold on some link in UIWebView ..it opens a UIActionSheet with three options open copy add to reading list ...I need to change this UIActionsheet controls like ..I need to add one more button into this ...how to do that...how to disable this and add new UIActionSheet according to my choice...

代码

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *requestURL = [ request URL];

if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
    // Call your custom actionsheet and use the requestURL to do what you want :)


    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Contextual Menu"
                                                       delegate:self cancelButtonTitle:@"Cancel"
                                         destructiveButtonTitle:nil otherButtonTitles:nil];

    [sheet addButtonWithTitle:@"Save Page as Bookmark"];
    [sheet addButtonWithTitle:@"Open Page in Safari"];

    [sheet showInView:webView];
    return NO;
}

return YES;
}


- (void)viewDidLoad
{
[super viewDidLoad];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];

webview.delegate=self;

}



- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {


if (buttonIndex == actionSheet.cancelButtonIndex) { return; }
switch (buttonIndex) {
    case 0:
    {
        NSLog(@"Item A Selected");
   NSLog(@"reg%@", request);

          NSURL *requestURL = [request URL];
        [webview loadRequest:[NSURLRequest requestWithURL:requestURL]];



        break;
    }
    case 1:
    {
        NSLog(@"Item B Selected");


        break;
    }

}

}

推荐答案

你可以这样做,点击链接并使用你的操作表

You can do like this , catch a tap on link and use your actionsheet then

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
    NSURL *requestURL = [ request URL];

    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        // Call your custom actionsheet and use the requestURL to do what you want :)
        return NO;
    }

    return YES;
}


- (void)viewDidLoad
{
    [super viewDidLoad];


     webview.delegate=self;
     [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];



}

这篇关于如何更改 UIWebView Tap 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆