作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经将 UIWebView 子类化,这样我就可以获得触摸事件并实现了这个方便的方法。我很好奇,这是否适用于实际的 iOS 设备。我不在办公室,所以我不知道是否在。它似乎在模拟器中工作。
- (void) tapAtPoint:(CGPoint)point
{
id /*UIWebBrowserView*/ webBrowserView = nil;
id webViewInternal = nil;
object_getInstanceVariable(self, "_internal", (void **)&webViewInternal);
object_getInstanceVariable(webViewInternal, "browserView", (void **)&webBrowserView);
if (webBrowserView) {
[webBrowserView tapInteractionWithLocation:point];
}
}
有没有人试过这样的东西?我肯定会在早上发现,哈哈。
最佳答案
请试试这段代码,它工作正常。
/* TapDetectingWindow.m */
#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(forwardTapwithObject:pointArray afterDelay:0.5];
}
else if (touch.tapCount > 1) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap  object:pointArray];
}
}
@end
/* WebViewController.h */
@interface WebViewController : UIViewController<TapDetectingWindowDelegate> {
IBOutlet UIWebView *mHtmlViewer;
TapDetectingWindow *mWindow;
}
/* WebViewController.m */
- (void)viewDidLoad {
[super viewDidLoad];
mWindow = (TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0];
mWindow.viewToObserve = mHtmlViewer;
mWindow.controllerThatObserves = self;
}
- (void)userDidTapWebView:(id)tapPoint
{
NSLog(@"TapPoint = %f, %f", tapPoint.x, tapPoint.y);
}
谢谢,如果您遇到任何问题,请告诉我。
关于objective-c - UIWebView 子类上的 tapAtPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11093431/
我正在编写测试,我想通过滑动来删除 tableViewCell,从而暴露红色的“删除”编辑操作。我可以很好地滑动单元格,但是当我尝试使用 tapAtPoint 时,问题就出现了。 这直接来自GREYA
我已经将 UIWebView 子类化,这样我就可以获得触摸事件并实现了这个方便的方法。我很好奇,这是否适用于实际的 iOS 设备。我不在办公室,所以我不知道是否在。它似乎在模拟器中工作。 - (voi
我是一名优秀的程序员,十分优秀!