功能模块IOS三人行

UILongPressGestureRecognizer长按手势

2015-12-19  本文已影响3080人  面试小集

长按手势(UILongPressGestureRecognizer)简介

长按手势一定需要和UIGestureRecognizer类的state属性进行配合使用,即通过不同状态state下,实现不同的功能。UIGestureRecognizer类的state属性中,常见的有:

//长按手势
 UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
 [self.imageView addGestureRecognizer:longPressGesture];
//响应事件
-(void) longPress: (UILongPressGestureRecognizer *) gesture {
 if (gesture.state == UIGestureRecognizerStateBegan) {
 NSLog(@"长按开始");
 self.longPressLable.text = @"长按开始";
 }else if (gesture.state == UIGestureRecognizerStateEnded){
 NSLog(@"长按结束");
 self.longPressLable.text = @"长按结束";
 }
 else {
 NSLog(@"长按中");
 self.longPressLable.text = @"长按中";
 }
}
上一篇下一篇

猜你喜欢

热点阅读