【问题标题】:How to allow UITapGestureRecognizer to detect taps on web view?如何允许 UITapGestureRecognizer 检测 Web 视图上的点击?
【发布时间】:2014-08-26 06:21:40
【问题描述】:

我在 Xcode 中为 iPhone 制作了网络浏览器,要退出网络浏览器并返回主页面,请在屏幕上点按 3 次,但手势仅适用于顶部和底部的工具栏屏幕上,但不在网络视图上。

我能做什么?

这是我的代码

.h 文件

#import <UIKit/UIKit.h>

@interface Internet : UIViewController {


IBOutlet UIWebView *webview;
IBOutlet UIBarButtonItem *forwards;
IBOutlet UIBarButtonItem *backwards;
IBOutlet UITextField *URLTextField;

}

- (IBAction)share:(id)sender;

- (IBAction)returnKeyPressed:(id)sender;
- (IBAction)google:(id)sender;
- (IBAction)reload:(id)sender;
- (IBAction)forwardsButton:(id)sender;
- (IBAction)backwardsButton:(id)sender;



@end

.m 文件(仅显示相关代码)

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    NSString *homePageString = @"http://www.google.com";
    NSURL *homePage = [NSURL URLWithString:homePageString];
    NSURLRequest *requestHomePage = [NSURLRequest requestWithURL:homePage];
    [webview loadRequest:requestHomePage];
    forwards.enabled = NO;
    backwards.enabled = NO;
    UIAlertView *touchHelp = [[UIAlertView alloc] initWithTitle:@"Alert, Please Read" message:@"To go back to the App Selection Page please anywhere on the top or bottom toolbar three times" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
    [touchHelp show];
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
    tapRecognizer.numberOfTapsRequired = 3;
    [self.view addGestureRecognizer:tapRecognizer];
}

- (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer {
    [self dismissViewControllerAnimated:YES completion:nil];
}

【问题讨论】:

    标签: iphone xcode uiwebview gestures


    【解决方案1】:

    实现shouldRecognizeSimultaneouslyWithGestureRecognizer委托并返回YES

    实现细节:

    UIGestureRecognizerDelegate 协议添加到您的.h 文件中

    @interface ViewController : UIViewController <UIGestureRecognizerDelegate>
    

    将此委托添加到您的 .m 文件中

    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
     {
        return YES
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 2013-03-26
      相关资源
      最近更新 更多