本文介绍了在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自定义单元格中的图像上长按手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:12