user6631314 user6631314 - 2 months ago 6
iOS Question

IOS: animage change in bounds of rectangle holding tableview

I have a

tableview
that I move up or down depending on the presence of a search bar. The movement is jerky,as it stands, and I would like to animate it if possible. Can anyone suggest how to animate a change in bounds? Here is the code that moves the table view

CGRect newBounds = self.tableView.bounds;
newBounds.origin.y = newBounds.origin.y - self.searchBar.bounds.size.height;
self.tableView.bounds = newBounds;

Answer

Try following code to animate your bound changes, let me know if this resolve your issue.

 CGRect newBounds = self.tableView.bounds;
    [UIView animateWithDuration:1.0
            delay: 0.0
            options: UIViewAnimationOptionCurveEaseIn
            animations:^{
               newBounds.origin.y = newBounds.origin.y - self.searchBar.bounds.size.height;
       self.tableView.bounds = newBounds;

            }
            completion:^(BOOL finished){
                // do something after animation finishes. 

            }];
Comments