cocos2dx怎么响应双击事件
推荐于2016-05-19 · 知道合伙人互联网行家
关注
展开全部
大致的代码如下:
Javascript:
function myClick() {
var e = window.event
var url = "click:" + e.target.id;
document.location = url;
}
var ele = document.getElementById(ELEMENT_ID);
ele.onclick = myClick;
CocoaTouch:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if (components.count == 2 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"click"]) {
NSString *eleIdStr = (NSString *)[components objectAtIndex:1];
NSInteger eleId = [eleIdStr integerValue];
// Do something
return NO; // Do not load request, just receive the event
}
return YES;
}
双击事件
Failed 1
使用与上面同样的方法为html元素添加ondblclick来响应双击事件就无法实现, 现象为响应函数从不被调用. 用setTimeout等方法尝试用单击事件来模拟双击事件也无法实现, 无法接收到double tap的第二次点击.
Failed 2
根据之前的现象来看, 显然双击事件在html之外就被拦截了, 要从CocoaTouch层下手才行.
系统的UIWebView中包含了一个UIScrollView, 绑定了UIScrollViewDelayedTouchesBeganGestureRecognizer和UIScrollViewPanGestureRecognizer这两个事件, 后者响应拖动事件, 前者相应点击事件.
尝试添给UIScrollView加UITapGestureRecognizer:
UITapGestureRecognizer *dblTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fakeTapGestureHandler:)];
经测试, fakeTapGestureHandler:从未被调用过.
Success
尝试曲线救国的方式, 用UIGestureRecognizer的delegate方法获取事件:
Javascript:
function eleIdFromPoint(x, y) {
var ele = document.elementFromPoint(x, y)
return "" + ele.id;
}
Javascript:
function myClick() {
var e = window.event
var url = "click:" + e.target.id;
document.location = url;
}
var ele = document.getElementById(ELEMENT_ID);
ele.onclick = myClick;
CocoaTouch:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if (components.count == 2 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"click"]) {
NSString *eleIdStr = (NSString *)[components objectAtIndex:1];
NSInteger eleId = [eleIdStr integerValue];
// Do something
return NO; // Do not load request, just receive the event
}
return YES;
}
双击事件
Failed 1
使用与上面同样的方法为html元素添加ondblclick来响应双击事件就无法实现, 现象为响应函数从不被调用. 用setTimeout等方法尝试用单击事件来模拟双击事件也无法实现, 无法接收到double tap的第二次点击.
Failed 2
根据之前的现象来看, 显然双击事件在html之外就被拦截了, 要从CocoaTouch层下手才行.
系统的UIWebView中包含了一个UIScrollView, 绑定了UIScrollViewDelayedTouchesBeganGestureRecognizer和UIScrollViewPanGestureRecognizer这两个事件, 后者响应拖动事件, 前者相应点击事件.
尝试添给UIScrollView加UITapGestureRecognizer:
UITapGestureRecognizer *dblTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fakeTapGestureHandler:)];
经测试, fakeTapGestureHandler:从未被调用过.
Success
尝试曲线救国的方式, 用UIGestureRecognizer的delegate方法获取事件:
Javascript:
function eleIdFromPoint(x, y) {
var ele = document.elementFromPoint(x, y)
return "" + ele.id;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询