如何对按钮单击事件执行两项操作。例如,单击一次我执行一项操作,连续两次单击我必须执行另一个事件。
问问题
96 次
4 回答
1
UIImageView
在.上使用双击手势..... 不要忘记将UIImageView's
UserInteractionEnabled 设置为TRUE。
ImageView.userInteractionEnabled = YES;
于 2013-01-17T14:28:37.670 回答
1
将初始按钮标签设置为 0
然后
-(IBAction)yourBtnPress:(id)sender
{
UIButton *btn = (UIButton*)sender;
if (btn.tag==0)
{
btn.tag=1;
//singlePress
}
else if(btn.tag==1)
{
//double tap
//if you want other action then change tag
btn.tag=2;
//if you restart task then
btn.tag=0;
}
}
于 2013-01-17T14:44:02.033 回答
1
这里tapCount是在.h 文件int
中声明的变量
- (void)viewDidLoad
{
tapCount = 0; // Count tap on Slider
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ButtonTap:)];
[button addGestureRecognizer:gr];
}
- (void)ButtonTap:(UIGestureRecognizer *)g
{
/////////////// For TapCount////////////
tapCount = tapCount + 1;
NSLog(@"Tap Count -- %d",tapCount);
/////////////// For TapCount////////////
if (tapCount == 1)
{
// code for first tap
}
else if (tapCount == 2)
{
// Code for second tap
}
}
于 2013-01-17T14:32:57.510 回答
0
您可以使用条件setAction:
如果单击然后调用selectorSingleTouch
。
否则打电话selectorDoubleTouch
。
//这不是编译器检查...至少你可以从中得到一些想法
UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)];
singleTap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:singleTap];
UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doDoubleTap)];
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
于 2013-01-17T14:23:31.290 回答