简体   繁体   English

在Tableview自定义单元格中的图像上长按手势

[英]Long press gesture on image in tableview custom cell

I need some help. 我需要协助。 Today, I am working on table view custom cell where the cell contains an UIImageView . 今天,我正在处理表格视图自定义单元格,其中该单元格包含一个UIImageView On the ImageView, I want to implement the long gesture. 我要在ImageView上实现长手势。 I implement code for this that is give below.. But I am doing something wrong in my code.In this the View is resize once on long press but i want after the some seconds it can be remove and come back in table view cell Can anyone Suggest me???? 我实现下面给出的代码。但是我在代码中做错了。在这种情况下,长按一次即可重新调整视图的大小,但是我希望在几秒钟后可以将其删除并返回到表格视图单元格中有人建议我吗???

Update: 更新:

长手势图像

Here's the code! 这是代码!

- (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;
}
[cell addGestureRecognizer:gesture1]

replace with below line 用下面的行替换

[ cell.yourimageview setUserInteractionEnabled:YES];  // This enable user interaction on the image view. Required!!


[cell.yourimageview addGestureRecognizer:gesture1];  //yourimageview is your image outlet

尝试一下:单元格是imageView的超级视图,因此在更改大小时不会改变单元格的大小,而是在调整大小后将其添加到mainView中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Tableview Cell上长按手势时禁用didSelectRowAtIndexPath - Disable didSelectRowAtIndexPath on Long press gesture on Tableview Cell 如何将长按手势识别器添加到tableview单元格内的按钮? - How to add long press gesture recognizer to a button inside of tableview cell? 无法在TableView上设置自定义长按手势识别器 - Cannot set custom Long Press Gesture Recognizer on TableView 使用长按手势来重新排列表格视图中的单元格? - Using long press gesture to reorder cells in tableview? iOS TableView长按Gesture去做电镀路径 - iOS TableView Long press Gesture going to didselectrowatIndexpath 在表格视图单元格上长按手势 - long press gesture on table view cell 当我们在iOS中长按手势时拥有TableView单元格的索引路径时,如何在单元格中将按钮的引用作为子视图 - How to get the button's reference in the cell as a subview when we have indexpath for tableview cell on long press gesture in ios 长按手势在UIButton中显示图像 - Show an image in a UIButton on long press gesture 当我在表格视图单元格中的uiimageview上添加长按手势时,Uiimageview没有显示正确的图像 - when I am adding Long Press Gesture on uiimageview in Table View Cell .Uiimageview Is not showing With correct Image 在Tableview中长按手势可增加应用程序的内存利用率 - Long Press Gesture in tableview increase app memory utilisation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM