Question

After a trigger I am attaching a custom view to a tableView.tableHeaderView property. The custom view is 50 pixels high. I want that table view to animate down nicely so that it is clear in 1 second interval that the tableview is making space for that view..The custom view should "push down" that tableview in a smooth way.

Any ideas how to do that?

No correct solution

OTHER TIPS

You can animate the headerView height the desired height:

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.frame.size.width, 10.0);
self.tableView.tableHeaderView = headerView;

// Add your subview(s)
...


// Animate to the new height (50px)

CGRect headerViewFrame = CGRectMake(0.0, 0.0, self.tableView.frame.size.width, 50.0);

[UIView animateWithDuration:1.0 animations:^{ headerView.frame = headerViewFrame; } completion:^(BOOL finished) {
     self.tableView.tableHeaderView = headerView;
}];

You can do it like this,

first take a header view in controller.m file

 @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
 {
     UIView *headerView;//view for header
    
 }

 - (void)viewDidLoad
 {
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    headerView.backgroundColor = [UIColor greenColor];

    self.tableView.tableHeaderView = headerView;
    self.tableView.tableHeaderView.frame = CGRectZero;
    [self.tableView setContentInset:UIEdgeInsetsMake(-50, 0, 0, 0)];//hear u set it above 50 top
 }

  - (void)actionTriggered
   {
     [UIView animateWithDuration:1.0 animations:^{   
        self.tableView.tableHeaderView.frame = CGRectMake(0, 0, 320, 50);
       [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
   
       } completion:^(BOOL finished) {
         [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
      }]; 
   }


  

hope this helps You ... :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top