@interface MyBrowser: UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *webView;
}
@property(nonatomic,retain) IBOutlet UIWebView *webView;
@end
我有一个类和一个UIWebView,当我触摸我的网络浏览器时,我想使用 - touchesBegan 事件...但我不能因为那个事件没有上升。 ..谁知道为什么那个事件没有上升,我必须做些什么来获得它!!!
答案 0 :(得分:0)
答案 1 :(得分:0)
#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
但是当我想运行我的应用程序时,找不到TapDetectingWindow的协议声明错误!这是什么意思 ???我必须做什么?