我刚开始接触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];
我该如何添加这两个事件呢? 任何帮助都将不胜感激。