在iOS 8中使用WKWebView,如何从本机端运行JavaScript函数或以其他方式从本机端到JavaScript进行通信?似乎没有类似于UIWebView的方法stringByEvaluatingJavaScriptFromString:.
(我可以- addScriptMessageHandler:name:在configuration.userContentController对象上使用以允许从JS到本地的通信,但我正在寻找相反的方向.)
我正在开发一种游戏,通过长按对象本身来设置游戏对象的属性.属性的值由长按手势的持续时间确定.我正在使用UILongPressGestureRecognizer来实现这个目的,所以它是这样的:
[gameObjectView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handle:)]];
Run Code Online (Sandbox Code Playgroud)
然后是处理函数
- (void)handle:(UILongPressGestureRecognizer)gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
// Get the duration of the gesture and calculate the value for the attribute
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何获得长按手势的持续时间?