UILongPressGestureRecognizer有不同的按钮
问题描述:
我有2个按钮与 “UILongPressGestureRecognizer”,要做到这一点,我做的:UILongPressGestureRecognizer有不同的按钮
Fot的按钮1:
-(IBAction)seleccionar46:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[self.button1 addGestureRecognizer:longpressGesture];}
对于按钮2:
-(IBAction)seleccionar46:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[self.button2 addGestureRecognizer:longpressGesture];}
而且在“longpressGesture”我需要区分button1和button2,但我不能这样做...
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{//Here i need do the differentation}
谢谢大家!
此致敬礼。
答
你可以做的是使用UIGestureRecognizer
的view
属性,所以如果你保存对两个按钮的引用,你可以检查是否相等。
所以,如果你有
@interface blah
{
UIButton *buttonOne;
UIButton *buttonTwo;
}
那么你识别器添加到您可以在处理程序
if(gestureRecognizer.view==buttonOne)
{
//do stuff for button one
}
else if(gestureRecognizer.view==buttonTwo)
{
//do stuff for button two
}
希望它有助于
感谢朋友做的按钮!我需要保存名称NSSttring中的按钮...我该怎么做? – 2012-02-13 19:10:18
为什么这样做?... – Daniel 2012-02-13 19:17:14
因为按钮的名称与一个图像的名称相同...而当我按下按钮3秒钟时,它会显示与按钮相关的图像...我希望你可以不言而喻...感谢所有丹尼尔 – 2012-02-13 19:21:38