UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(btnLong:)];
longPress.minimumPressDuration = 0.5; //定义按的时间
[btn addGestureRecognizer:longPress];
-(void)btnLong:(UILongPressGestureRecognizer *)gestureRecognizer{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
NSLog(@"长按开始");
} else if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {
NSLog(@"长按结束");
}
}