#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のプロトコル宣言が見つかりましたエラーが表示されます!どういう意味ですか ???私は何をしなければならないのですか?
.mファイルに 'self.webView.delegate = self'を設定してみてください。 –