如何在iphone的UIWebBrowser中提升触控开始事件
我有一个类和一个UIWebView,我想在触摸我的web浏览器时使用-touchesbeent事件。。。但我不能因为那件事没有发生。。。谁知道为什么那个事件没有发生,我必须做什么才能得到它 这是我找到的最好的帖子- 当我添加此代码时,我会将此代码添加到我的应用程序中:如何在iphone的UIWebBrowser中提升触控开始事件,iphone,uiwebview,uiviewcontroller,Iphone,Uiwebview,Uiviewcontroller,我有一个类和一个UIWebView,我想在触摸我的web浏览器时使用-touchesbeent事件。。。但我不能因为那件事没有发生。。。谁知道为什么那个事件没有发生,我必须做什么才能得到它 这是我找到的最好的帖子- 当我添加此代码时,我会将此代码添加到我的应用程序中: #import <UIKit/UIKit.h> @protocol TapDetectingWindowDelegate - (void)userDidTapWebView:(id)tapPoint; @end @
#import <UIKit/UIKit.h>
@protocol TapDetectingWindowDelegate
- (void)userDidTapWebView:(id)tapPoint; @end
@interface TapDetectingWindow : UIWindow {
UIView *viewToObserve;
id <TapDetectingWindowDelegate> controllerThatObserves; } @property (nonatomic, retain) UIView
*viewToObserve; @property (nonatomic, assign) id <TapDetectingWindowDelegate> controllerThatObserves;
@end
#import "TapDetectingWindow.h"
@implementation TapDetectingWindow
@synthesize viewToObserve;
@synthesize controllerThatObserves;
- (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate {
if(self == [super init]) {
self.viewToObserve = view;
self.controllerThatObserves = delegate;
}
return self;
}
- (void)dealloc {
[viewToObserve release];
[super dealloc];
}
- (void)forwardTap:(id)touch {
[controllerThatObserves userDidTapWebView:touch];
}
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
if (viewToObserve == nil || controllerThatObserves == nil)
return;
NSSet *touches = [event allTouches];
if (touches.count != 1)
return;
UITouch *touch = touches.anyObject;
if (touch.phase != UITouchPhaseEnded)
return;
if ([touch.view isDescendantOfView:viewToObserve] == NO)
return;
CGPoint tapPoint = [touch locationInView:viewToObserve];
NSLog(@"TapPoint = %f, %f", tapPoint.x, tapPoint.y);
NSArray *pointArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", tapPoint.x],
[NSString stringWithFormat:@"%f", tapPoint.y], nil];
if (touch.tapCount == 1) {
[self performSelector:@selector(forwardTap:) withObject:pointArray afterDelay:0.5];
}
else if (touch.tapCount > 1) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap:) object:pointArray];
}
}
@end
但当我想运行我的应用程序时,无法找到用于TapDetecting的协议声明窗口错误出现!!!这是什么意思???我必须做什么?尝试在.m文件中设置self.webView.delegate=self。我尝试像示例中那样做,但当我要运行应用程序时,找不到用于TapDetecting的协议声明。出现错误窗口!!!
#import <UIKit/UIKit.h>
@protocol TapDetectingWindowDelegate
- (void)userDidTapWebView:(id)tapPoint; @end
@interface TapDetectingWindow : UIWindow {
UIView *viewToObserve;
id <TapDetectingWindowDelegate> controllerThatObserves; } @property (nonatomic, retain) UIView
*viewToObserve; @property (nonatomic, assign) id <TapDetectingWindowDelegate> controllerThatObserves;
@end
#import "TapDetectingWindow.h"
@implementation TapDetectingWindow
@synthesize viewToObserve;
@synthesize controllerThatObserves;
- (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate {
if(self == [super init]) {
self.viewToObserve = view;
self.controllerThatObserves = delegate;
}
return self;
}
- (void)dealloc {
[viewToObserve release];
[super dealloc];
}
- (void)forwardTap:(id)touch {
[controllerThatObserves userDidTapWebView:touch];
}
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
if (viewToObserve == nil || controllerThatObserves == nil)
return;
NSSet *touches = [event allTouches];
if (touches.count != 1)
return;
UITouch *touch = touches.anyObject;
if (touch.phase != UITouchPhaseEnded)
return;
if ([touch.view isDescendantOfView:viewToObserve] == NO)
return;
CGPoint tapPoint = [touch locationInView:viewToObserve];
NSLog(@"TapPoint = %f, %f", tapPoint.x, tapPoint.y);
NSArray *pointArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", tapPoint.x],
[NSString stringWithFormat:@"%f", tapPoint.y], nil];
if (touch.tapCount == 1) {
[self performSelector:@selector(forwardTap:) withObject:pointArray afterDelay:0.5];
}
else if (touch.tapCount > 1) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap:) object:pointArray];
}
}
@end
@interface MiniBrowser : UIViewController <UIWebViewDelegate, TapDetectingWindow>{ IBOutlet UIWebView *webView; }
@property(nonatomic,retain) IBOutlet UIWebView *webView;
@end