1

I need some help. Today, I am working on table view custom cell where the cell contains an UIImageView. On the ImageView, I want to implement the long gesture. 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:

long gesture Image

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];
}
Krunal
  • 77,632
  • 48
  • 245
  • 261
  • Show the resulting output and code which you have write for the same. – Bhadresh Mulsaniya Jul 27 '16 at 10:55
  • clipSubviews may be checked on the CustomCell! Try to disable that either is cellForRowAtIndexPath() or in the Interface Builder if using prototype cells! – Ariel Jul 27 '16 at 11:03
  • Attache images plz – Ahmed Abdallah Jul 27 '16 at 11:05
  • @simerkaur You should not post codes and images in the comment section. Post it in the Questions for more detail please! – Ariel Jul 27 '16 at 11:05
  • in method of gesture if (gesture.state == UIGestureRecognizerStateBegan) { UITableViewCell *cell = (UITableViewCell *)[gesture view]; } 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(30, 0, 300 , 300); } – simer kaur Jul 27 '16 at 11:06

3 Answers3

0
        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;
}
Saurabh Jain
  • 1,688
  • 14
  • 28
-1
[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
Ariel
  • 2,471
  • 1
  • 26
  • 43
Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25
-1

Try it: Cell is superView of imageView so on size changing it will not cross cell frame add it to mainView after resize.

jagdish
  • 166
  • 5
  • Please provide exception message – jagdish Jul 27 '16 at 12:42
  • This occur when a class does not respond to a method. before calling check if([ActivityFeedViewController instancesRespondToSelector:@selector(celllongpressed:)]){ / } – jagdish Jul 27 '16 at 12:55