开发者

how to zoom a cell in a tableview

i am developing an app in which i have taken a tableview to display images in the cells. i have given the size of a cell as the size of the ipad screen,and taken care when i scroll the tableview,it scrolls to next cell.now i want to zoom each and every cell as i have a requirement. To achieve it i have taken a scrollview and placed it on the content view of the cell,and placed the images on the scrollview.

issue: the issue i am facing is the zoom is not being performed on the cell.the gesture delegate method is not even being invoked. i was surprised with that and started searching in a web " whether we can zoom a cell in a table view".but could not find many results.

can someone suggest me if there is a way to zoom a cell开发者_如何学C in a tableview? can't we place a scrollview in a tableview cell?

any approach is appreciated.

TNQ


I am also facing this issue. I solve this issue by following way: I have added Pinch gesture recognizer to cell of tableView and applied following code :

- (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer {

  if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||   [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
      [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
      [gestureRecognizer setScale:1];
  }
  else if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
  {
    if([gestureRecognizer view].transform.b<0 && [gestureRecognizer view].transform.c<1)
    {
        [gestureRecognizer view].transform=CGAffineTransformMake(0,-1.0,1.0,0,0,0);
    }
    [gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
    [gestureRecognizer setScale:1];

  }
}


i am finally answering my own question after waiting for few days. as i said in the question that i want to zoom the content in the cell of the table view, which i figured out is impossible.

i tried placing a scrollview inside the cell of the tableview,and tried to zoom but the gesture recognizer could not recognize the gesture as it was confused between the table view scroll and my scrollview. after spending time googling and with my own experience with table view and scroll i made a conclusion that i cannot zoom the content of a table view cell.

i solved my case by assigning a pinch gesture to the super view of tableview (scroll view is my superview). as soon as pinch is recognized i am copying the content of the content view of the table view cell into a view and adding it to the super view i.e scroll view and thus zooming the view. later after the zoom is performed and scale reduces to one, i remove the view from super view.

in this way i solved my case.

hope it would help others with a scenario like mine

TNQ


take a variable

NSInteger selectedindex

Now put this thing in

 - (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   //whatever your code write here

   if (selectedindex == indexPath.row) {
         [self animateZoomforCell:cell];
   }else
   {
         [self animateZoomforCellremove:cell];
   } 
   return cell;
 }

 - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //whatever your code write here

  selectedindex =indexPath.row; 
    [self.tableView reloadData];
 }

You can use this method for zooming in/out cell

  -(void)animateZoomforCell:(UITableViewCell*)zoomCell {
       [UIView animateWithDuration:0.2 delay:0  options:UIViewAnimationOptionCurveEaseOut
          animations:^{

       zoomCell.transform = CGAffineTransformMakeScale(1.6,1.6);
         } 
         completion:^(BOOL finished){
         }];
        }

   -(void)animateZoomforCellremove:(UITableViewCell*)zoomCell {
       [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        zoomCell.transform = CGAffineTransformMakeScale(1.0,1.0);
      }   
         completion:^(BOOL finished){
      }]; 
      }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜