gpt4 book ai didi

iphone - 使用 UIGestures 删除选定的 uiimage?

转载 作者:行者123 更新时间:2023-12-03 19:43:52 24 4
gpt4 key购买 nike

我正在尝试通过长按手势来删除图像...问题是我可以在同一 View 上有多个图像。并且可能想要通过按住图像来删除每个图像。

所以可以说我有:

 @property (nonatomic, retain) IBOutlet UIImageView *Image1;
@property (nonatomic, retain) IBOutlet UIImageView *Image2;
@property (nonatomic, retain) IBOutlet UIImageView *Image3;

所有内容都在同一 View 中。现在我按住 Image1。如何让长按手势知道我选择了 Image1 ??

- (void)handleDelete:(UILongPressGestureRecognizer *)recognizer {
//Something in here to detect image is selected and delete :)
}

谢谢!!!

最佳答案

在.h文件中提供UIGestureRecognizerDelegate,然后尝试此代码...

    UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 5;
[longpressGesture setDelegate:self];
[self.yourImages addGestureRecognizer:longpressGesture];
[longpressGesture release];

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
NSLog(@"longPressHandler");
UIImageView *tempImage=(UIImageView*)[gestureRecognizer view];
[tempImage removeFromSuperview];
}

关于iphone - 使用 UIGestures 删除选定的 uiimage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13187535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com