我需要在长按列表项时显示删除按钮.
我有长按的代码..但不知道如何编码在这个长按内显示一个按钮...
我们如何通过触摸事件来模拟长按?或者我们如何在ACTION_DOWN状态下计算触摸屏幕的时间?
我的应用程序是ios phonegap应用程序.我想从Web视图的文本字段中禁用复制和粘贴菜单.长按和双击,复制粘贴菜单显示.我尝试使用UIGestureRecognizer类禁用长按和双击:
- (void)viewDidLoad{
UILongPressGestureRecognizer* longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
[longPressGesture setMinimumPressDuration:0.2];
longPressGesture.delegate = self;
[self.webView addGestureRecognizer:longPressGesture];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
return NO;
}
else if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]){
return NO;
}
else
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但我无法禁用双击.任何人具有相同的查询?帮帮我...
我在viewController类级别定义了longPress和Pan手势识别器,如下所示:
var touch = UILongPressGestureRecognizer()
var pan = UIPanGestureRecognizer()
Run Code Online (Sandbox Code Playgroud)
然后我创建一个简单的UIView:
let qBox = UIView()
qBox.frame = CGRect(x: 100, y: 200, width: 50, height: 50)
self.view.addSubview(qBox)
Run Code Online (Sandbox Code Playgroud)
然后我配置并添加我的识别器:
touch.addTarget(self, action: "ourTouched:")
touch.minimumPressDuration = 0
touch.numberOfTouchesRequired = 1
touch.numberOfTapsRequired = 0
qBox.addGestureRecognizer(touch)
pan.addTarget(self, action:"pan:")
pan.maximumNumberOfTouches = 1
pan.minimumNumberOfTouches = 1
self.view.addGestureRecognizer(pan)
Run Code Online (Sandbox Code Playgroud)
现在,当我触摸qBox UIView时,它会触发"ourTouched"方法但是如果我继续按住然后开始平移,它将不会拖动qBox UIView.我尝试在我的"ourTouched"函数中添加以下行,以便在用户触摸qBox UIView时立即删除长按识别器:
qBox.removeGestureRecognizer(touch)
Run Code Online (Sandbox Code Playgroud)
但是,在第一次触摸和拖动时,只会调用长按方法.我必须放手,然后再次开始平移.我错过了什么?
我是android开发的新手。尝试提供平铺服务,但是我无法覆盖默认的长按操作。
为此,我有一个名为QSTileService的类,该类扩展了TileService,并且我希望我的tile根据您按下还是长按来执行不同的操作。香港专业教育学院到目前为止发现按钮的目的是实现OnLongClickListener接口并填写您要在onLongClick方法中执行的操作,但是我不确定如何使用快速设置图块执行此操作?
任何帮助将不胜感激
我有以下 angular2 模板:
<div (click)="foo()">
<img (longPress)="bar(1)" (click)="foobar(1)" />
<img (longPress)="bar(2)" (click)="foobar(2)"/>
</div>
Run Code Online (Sandbox Code Playgroud)
Longpress 是一个自定义属性指令,当鼠标按下 500 毫秒时触发。
<div>和上的点击事件<img>处理得很好。当我长按图像时,会调用 bar() 函数。但是,在 mouseUp 上(长按后),将在<img>和 父级上触发单击事件<div>。
如何以最简单的方式阻止这些点击事件。
我现在唯一能想到的就是编写一个自定义属性指令,仅在不到 500 毫秒的“点击”时触发。这对我来说似乎有点过分了。
我遇到了 UILongPressGestureRecognizer 的问题,我使用了以下代码:-
func addLongPressGesture(){
let lngPr = UILongPressGestureRecognizer.init(target: self, action: #selector(self.handleLongPress(gesture:)))
lngPr.delaysTouchesEnded = true
self.addGestureRecognizer(lngPr)
}
@objc func handleLongPress(gesture:UIGestureRecognizer){
if selectedIndexPath != nil && delegate != nil{
self.delegate?.delegateLongPressed(atIndexPath: selectedIndexPath!)
}
}
Run Code Online (Sandbox Code Playgroud) 简短版本:我想要一种方法在onTouchEvent上启动基于时间的计数器,并测试在响应之前是否已经过了一定的时间,作为手动LongTouch检测.
说明:我有一个自定义的imageView,可以在两指翻转的屏幕上滑入/滑出屏幕.我想向它添加拖动事件,但这些需要比长按更快.我可以通过使用每个onTouchEvent更新一次的计数器来延迟拖动事件,并且仅触发拖动,例如10次计数,但计数器仅更新触摸事件并且手指必须移动.
如何创建一个基于时间的计数器,一个活动级别字段,每秒递增60次或某些?
我是iPhone新手.
我想在我的按钮上添加长按手势和点击事件,这可能吗?
当我将两个事件添加到按钮然后长按时,我的点击事件被触发(点击我导航到新页面),但我的长按事件永远不会被触发.
这是我的代码片段:
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xpos, ypos, 120,130);
[button setBackgroundImage:[UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal];
[button setTitle:[NSString stringWithFormat:@"32"]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchDown];
LongPress = [[UILongPressGestureRecognizer alloc] init];
[LongPress addTarget:self action:@selector(longPressDetected:)];
LongPress.delegate = (id<UIGestureRecognizerDelegate>)self;
[button addGestureRecognizer:LongPress];
[LongPress release];
[self.view addSubview:button];
Run Code Online (Sandbox Code Playgroud)
如何添加这两个事件?
任何帮助将不胜感激.
我想用滚动"连接"长按,因此用户不必释放屏幕并开始滚动.
我有手势探测器实现...
final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
// action 1
}
public boolean onScroll(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
// action 2
}
}
public boolean onTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
但是现在在动作1和动作2之间,用户必须释放屏幕......如何在不释放屏幕的情况下连接此动作?