Search code examples
iosswiftuitableviewxibios-autolayout

Unable to show tableview from button press on UIView xib


In my app users profiles are contained on a xib file that is shown when the user taps a button on the Main View Controller. At the base of the xib pop-up is a button that shows user's the leaderboard tableview of scores of other users in their area. The issue I am facing is that on iPhone 8 the tableview is able to slide up and be shown however on iPhone X & iPhone 11 nothing happens. Below I will include a screenshot of the view hierarchy and constraintsenter image description here

The code inside the IBAction is executed as such

   @IBAction func userTappedScoresIcon(_ sender: Any) {

    //load tableview data
    score_tblView.reloadData()

    scoreViewTopConstraint.constant = 0.0

    UIView.animate(withDuration: 0.25) {
       self.scoresView.frame = self.profile_scroller.bounds

    }

}

I have tried changing the constraints in storyboard as well as removing the constraint at the top of the tableview but nothing has been successful. any help would be much appreciated!


Solution

  • You can try with this example

    self.topConstraint.constant = -100.0;    
    [self.viewToAnimate setNeedsUpdateConstraints]; 
    [UIView animateWithDuration:1.5 animations:^{
        [self.viewToAnimate layoutIfNeeded]; 
    }];
    
    func AnimateBackgroundHeight() {
       UIView.animateWithDuration(0.5, animations: {
           self.heightCon.constant = 600 // heightCon is the IBOutlet to the constraint
           self.view.layoutIfNeeded()    
       })
    }