Long press gesture on image in tableview custom cell(在Tableview自定义单元格中的图像上长按手势)
本文介绍了在Tableview自定义单元格中的图像上长按手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助。今天,我正在处理表视图自定义单元格,其中单元格包含UIImageView
。在ImageView上,我想实现Long手势。我实现了下面给出的代码。但我在我的代码中做了一些错误的事情。在这种情况下,长按一次视图就会调整大小,但我希望在几秒钟后它可以被删除,并在表格视图单元格中返回
有人能推荐我吗?
更新:
代码如下!
- (void)celllongpressed:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
cell = (ActivityFeedCell *)[gesture view];
}
if (gesture.state == UIGestureRecognizerStateChanged)
{
cell = (ActivityFeedCell *)[gesture view];
logGes_view=[[UIView alloc]initWithFrame:CGRectMake(5, 0,self.view.frame.size.width-10,self.view.frame.size.height)];
image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 80,self.view.frame.size.width, self.view.frame.size.height-80)];
image.image=cell.updated_imgView.image;
UILabel *name_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 15, 150, 30)];
//city_label.backgroundColor=[UIColor yellowColor];
name_label.text=lgGesNamelbl;
UILabel *city_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 180, 30)];
//city_label.backgroundColor=[UIColor yellowColor];
city_label.text=lgGesCitylbl;
[logGes_view addSubview:city_label];
[logGes_view addSubview:name_label];
[logGes_view addSubview:image];
logGes_view.backgroundColor=[UIColor whiteColor];
[self.view addSubview:logGes_view];
}
if (gesture.state == UIGestureRecognizerStateEnded)
{
// cell = (ActivityFeedCell *)[gesture view];
[logGes_view removeFromSuperview];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILongPressGestureRecognizer *gesture1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(celllongpressed:)];
[gesture1 setDelegate:self];
[gesture1 setMinimumPressDuration:1.0];
[ cell setUserInteractionEnabled:YES];
[cell addGestureRecognizer:gesture1];
}
推荐答案
UILongPressGestureRecognizer *reconizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
[reconizer setMinimumPressDuration:1.0];
[cell addGestureRecognizer:reconizer];
-(void)handleLongPress:(UILongPressGestureRecognizer*)reconizer
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
UITableViewCell *cell = (UITableViewCell *)[gesture view];
NSIndexPath *indexPath = [tableview indexPathForCell:cell];
NSString *s = [NSString stringWithFormat: @"row=%1ld",(long)indexPath.row];
[self setTitle: s];
}
if (gesture.state == UIGestureRecognizerStateChanged)
{
cell = (UITableViewCell *)[gesture view];
cell.updated_imgView.frame=CGRectMake(0, 0, tableview.frame.size.width, tableview.frame.size.height);
}
if (gesture.state == UIGestureRecognizerStateEnded)
{
cell = (UITableViewCell *)[gesture view];
cell.updated_imgView.frame=CGRectMake(0, 0, 100, 100);
}
}
-(BOOL)canBecomeFirstResponder
{
return YES;
}
这篇关于在Tableview自定义单元格中的图像上长按手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:在Tableview自定义单元格中的图像上长按手势


基础教程推荐
猜你喜欢
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01