iphone,应用程序认为我按了两次按钮
我上过这样的课iphone,应用程序认为我按了两次按钮,iphone,objective-c,uibutton,Iphone,Objective C,Uibutton,我上过这样的课 @interface UIGestureHolder : UILongPressGestureRecognizer { int tag; } @property (nonatomic, readwrite) int tag; @end @implementation UIGestureHolder @synthesize tag; @end 然后我将其分配给一个按钮,以便在按住按钮时调用buttonheld函数: UIGestureHolder *longpr
@interface UIGestureHolder : UILongPressGestureRecognizer {
int tag;
}
@property (nonatomic, readwrite) int tag;
@end
@implementation UIGestureHolder
@synthesize tag;
@end
然后我将其分配给一个按钮,以便在按住按钮时调用buttonheld函数:
UIGestureHolder *longpressGesture = [[UIGestureHolder alloc] initWithTarget:self action:@selector(buttonHeld:)];
longpressGesture.minimumPressDuration = 1.5;
[longpressGesture setDelegate:self];
longpressGesture.tag=i;
[contactButton addGestureRecognizer:longpressGesture];
[longpressGesture release];
Buttonheld函数:
-(void)buttonHeld:(id)sender
{
int i = ((UIControl *) sender).tag;
......
}
当我按住按钮1.5秒或任何我想要的时间时,运行时告诉我我按住按钮两次,每次1.5秒,为什么?这会导致我以后出现异常
为什么运行时认为我按住按钮两次?可能按钮也启用了单次点击?按钮行为是点击它一次&发生了什么事,对吗
将
响应程序分配给按钮时,您做了什么?尝试禁用它&看看你是否得到相同的…手势识别器会在状态改变时通知你。将代码更改为:
-(void)buttonHeld:(UILongPressGestureRecognizer*)longPressRecognizer
{
if(longPressRecognizer.state == UIGestureRecognizerStateBegan)
{
int i = ((UIControl *) sender).tag;
......
}
}