ios - 在表格 View 自定义单元格中的图像上长按手势

标签 ios objective-c uitableview uigesturerecognizer uilongpressgesturerecogni

我需要一些帮助。今天,我正在研究 TableView 自定义单元格,其中单元格包含一个 UIImageView。在 ImageView 上,我想实现长手势。我为此实现了下面给出的代码。但是我在我的代码中做错了。在此 View 中,长按会调整一次大小,但我希望几秒钟后它可以被删除并返回到表格 View 单元格中 任何人都可以建议我吗????

更新:

long gesture Image

这是代码!

- (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;
}

关于ios - 在表格 View 自定义单元格中的图像上长按手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38610913/

相关文章:

swift - 删除 viewController 的边距

iphone - 将图像添加到 IOS 上的联系人时令人费解的内存泄漏

objective-c - NSTask/Process 弃用的方法和属性

ios - 整理 MPMediaQuery 时转义标点符号和歌曲标题中的 'The' 前缀

swift - 自定义 UITableViewCell 中的 UIView 在滚动时重绘

iOS:如何访问 UISegmentedControl 中的各个段?

ios - 旋转时自动布局更新图像大小

ios - 在没有层次结构的两个 View Controller 之间切换

ios - taskWillPerformHTTPRedirection 从未在 Alamofire 5 中调用

ios - UIView 功能错误