Quantcast
Viewing all articles
Browse latest Browse all 5

Answer by Septronic for UITableViewCell animate resize when user touchdown or tap Cell

I was trying to achieve something similar to you. I was trying to show a portion of my UIImage in a UIImageView that I had added to my custom UITableViewCell, and had set the constraints to have my imageview the whole size of the cell (Similar to background, especially as you have a custom cell as well). I followed the answer @Joy had provided for this question, and created the following:

I added this to my viewDidLoad:

self.currentSelection = -1;// I changed his line below, so that the image resizing (cell resizing really) is constant for //all my images. I guess you can use this to resize your background back and forth to whatever size you want to.self.newCellHeight = self.tableView.frame.size.width*3/2;

Then I added these:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{//I added this to toggle a tap-tapagain kind of thing, so if the same cell is tapped twice, first tap expands and second tap collapses.      if (self.currentSelection==indexPath.row) {        self.currentSelection = -1;    }else{        self.currentSelection = indexPath.row;    }        // save height for full text label//    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];        // animate        [tableView beginUpdates];        [tableView endUpdates];}//The rest is pretty much the same as his code- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {    // do things with your cell here    // sentinel    self.currentSelection = -1;    // animate    [tableView beginUpdates];    [tableView endUpdates];}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    int rowHeight;    if ([indexPath row] == self.currentSelection) {        rowHeight = self.newCellHeight;    } else rowHeight = 100;    return rowHeight;}

One last thing, if you want to show the background to be centred, and to 'zoom' in and out from center. I'd set my imageview content mode to center, something like this:

[cell.myImageView setContentMode:UIViewContentModeCenter];

I learned a lot from @EmptyStack and @erkanyildiz answers to this question.

Anyway, I hope this helped in anyway, and sorry if none of it was relevant! :)


Viewing all articles
Browse latest Browse all 5

Trending Articles