0

Here is my screen. Consider the first row till Repeat switch :

enter image description here

Following is the switch action :

/**
Function name : repeatAction
Repeat UISwitch action
**/
@IBAction func repeatAction(sender: UISwitch)
{
    if sender.isOn
    {
        cellDateTime.constrain_viewRepeatHeight.constant = 80
        UIView.transition(with: self.cellDateTime.view_repeat, duration: 0.6, options: .transitionCrossDissolve, animations: {() -> Void in
                self.cellDateTime.view_repeat.isHidden = false
        }, completion: { _ in })
    }
    else
    {
        UIView.transition(with: self.cellDateTime.view_repeat, duration: 0.6, options: .transitionCrossDissolve, animations: {() -> Void in
                self.cellDateTime.view_repeat.isHidden = true
            }, completion: { _ in
                self.cellDateTime.constrain_viewRepeatHeight.constant = 0
        })
    }

let offset = self.table_InitialData.contentOffset
self.table_InitialData.layer.removeAllAnimations()
self.table_InitialData.beginUpdates()
self.table_InitialData.endUpdates()
self.table_InitialData.contentOffset = offset
}  

When switch is in on state for the first time, it works fine :

enter image description here

Now when the switch is in off state again, ideally it should appear as in the first screenshot. However, it looks like this :

enter image description here

I am using auto layouts. Just to mention, previously I had the same controls in a simple controller view and that worked fine. But since I placed them in UITableView, it is getting weird.

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • @vadian : Since the height of row is to be updated in this case, what should be the alternative ? – Nitish Mar 07 '17 at 18:01
  • Try setting the vertical and horizontal `contentHugging` priority of the `UIView` enclosing the time and *>* symbol to 1000 and giving a `>=` instead of a `=` constraint to your bottom most view in the cell. (Consider using `UITableViewAutomaticDimensions` if you aren't already). Without a better idea of how you are constraints are laid out inside the cell, a rough guess is the best that can be done :) – Rikh Mar 07 '17 at 18:27
  • 1
    @vadian - from Apple's Docs: "You can also use this method - beginUpdates() - followed by the endUpdates() method to animate the change in the row heights without reloading the cell." It's commonly used to do what the OP is trying to accomplish. – DonMag Mar 07 '17 at 19:18
  • @Nitish - can you reduce your code to a reproducible example? It would be a lot easier to help figure out what's not-quite-right.... – DonMag Mar 07 '17 at 19:19
  • @DonMag : I tried with just beginUpdates/endUpdates. Same issue along with scroll position lost. – Nitish Mar 08 '17 at 04:22
  • Try moving all the code outside the animations to be called when the completion block is called after the animation. Right now they are executing immediately – agibson007 Mar 09 '17 at 20:38
  • @Nitish - did yo get this resolved? If not, I can give you a working example to build on. – DonMag Mar 10 '17 at 17:37

0 Answers0