//
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 给imageView添加手势
self.imageView.userInteractionEnabled = YES;
// 创建『长按』手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.imageView addGestureRecognizer:longPress];
}
/**
* 长按手势默认会触发2次(所以我们需要判断一下手势的状态)
*/
- (void)longPress:(UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan) {
NSLog(@"长按了");
}
}
@end
手势识别器(UIGestureRecognizer)- UILongPressGestureRecognizer(长按)
最新推荐文章于 2024-05-16 11:10:59 发布