1

I am banging my head around this issue for quite a time. I have aUITableViewCell that contains 2 UIImageView's. look like this:

enter image description here

Now the way it works is that when I slide with my finger on one of the pictures, that picture should expand it's width to the other side of the screen and it's height should enlarge to the size of the expanded width to make it even (I am using UIPanGestureRecognizer), which requires the UITableViewCell to enlarge too.

But for some reason I have not managed to accomplish this presumably simple task. and although the UiImageView's are enlarging as I want, but the UITableViewCell height - remains static. which results in the bottom of the cell getting hidden

Based on suggestions to similar questions asked in stack overflow, I have tried the following, yet I still cannot resolve the issue.

I have added the following snippet of code in my viewDidLoad:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 470

but not only this did not solve the problem, Now with the automatic height most of the cell is hidden and only the top is shown. seems like for some reason it requires a static row height but then again How do I cause the cell height to enlarge in response to UIImageView enlargement within the cell.

RoHaN
  • 372
  • 3
  • 14
Hudi Ilfeld
  • 1,905
  • 2
  • 16
  • 25
  • When using `UITableViewAutomaticDimension` you should be careful to add all the vertical constraints for all the elements. Because that's how table view will calculate cell height by using constraint constants.Can you share how did you expand your image height? – DionizB Nov 09 '18 at 11:07
  • the 2 images are inside of a UIView container and the view container has a constraint height and every time I pan, I'm increasing the NSLayoutConstraint outlet constant `self.picsContainerHeight.constant = self.picsContainer.frame.width` – Hudi Ilfeld Nov 09 '18 at 11:19
  • Did you try reloading current table cell while detecting `UIPanGestureRecognizer`, or beginning tableView updates after Pan Gesture is detected? – DionizB Nov 09 '18 at 11:24
  • yes. it doesn't help – Hudi Ilfeld Nov 09 '18 at 12:09
  • are you reloading this row after pan gesture is applied to the cell ?? , if not try to reload the row. – MhmdRizk Nov 09 '18 at 12:21
  • yes. I added `self.tableView.reloadRows(at: [self.currentIndexPath], with: .none)` but nothing changes – Hudi Ilfeld Nov 09 '18 at 12:45
  • Possible duplicate of [Can you animate a height change on a UITableViewCell when selected?](https://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected) – hfehrmann Nov 09 '18 at 12:51

1 Answers1

0

You should call tableView.beginUpdates(); tableView.endUpdates() at the end of animation and make sure that the cell is constrained to every edge (self-sizing cell).

This is documented in beginUpdates method

... You can also use this method followed by the endUpdates() method to animate the change in the row heights without reloading the cell. ...

hfehrmann
  • 457
  • 3
  • 13
  • my UIViews are constrained to the the Content View, but I the interface builder doesn't allow me to constrain my Cell or my Content View – Hudi Ilfeld Nov 09 '18 at 13:13
  • That is OK. The important thing is that every vertical constraint is setted so the cell can calculate the height itself. Search for self-sizing cells on iOS. There is plenty of information. – hfehrmann Nov 09 '18 at 13:27