首先添加手势方法
// 长按手势
- (void)addLongGes
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionLongPress:)];
// 最短长按时间
longPress.minimumPressDuration = 1;
[_imageLeftIV addGestureRecognizer:longPress];
}
// 长按手势 (常用)
- (void)actionLongPress:(UILongPressGestureRecognizer *)longPress
{
// 根据手势的状态判断,只有第一次执行时是UIGestureRecognizerStateBegan,其余都是UIGestureRecognizerStateEnd状态。
if (longPress.state == UIGestureRecognizerStateBegan) {
// 长按 换张图片
// 获取到长按的view
UIImageView *imageView = (UIImageView *)longPress.view;
imageView.image = [UIImage imageNamed:@"Selected"];
}
}