Domanda

I have a UIViewController holding UITableView stretched on all it's area. On bar button click I'm trying to shrink and move and shrink the UITableView to make a space for UIView that is moving down from the top of the screen.

I attach thee project project

I manage to move red view just fine, but having problems with moving and resizing UITableView stimulatenously.

Here are my animations that cause problems.

-(void)extendTableView
{
    if (searchPanel) {        
        objectsTableView.frame = CGRectMake(objectsTableView.frame.origin.x, 0, objectsTableView.frame.size.width, 100);
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.5];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromTop];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setDelegate: self];
        [animation setValue:ANIMATION_EXTEND_TABLE_VIEW forKey:KEY_ANIMATION];
        [objectsTableView.layer addAnimation:animation forKey:ANIMATION_EXTEND_TABLE_VIEW];

    }

-(void)shrinkTableView
{
    if (searchPanel) {
        objectsTableView.frame = CGRectMake(objectsTableView.frame.origin.x, 100, objectsTableView.frame.size.width, 100);
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.5];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromBottom];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setDelegate: self];
        [animation setValue:ANIMATION_SHRINK_TABLE_VIEW forKey:KEY_ANIMATION];
        [objectsTableView.layer  addAnimation:animation forKey:ANIMATION_SHRINK_TABLE_VIEW];
    }
}

What would be the proper way to achieve that?

È stato utile?

Soluzione

This works perfect

   -(void)extendTableView
    {
        if (searchPanel) {
            CGRect screenRect = [[UIScreen mainScreen] bounds];
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            objectsTableView.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
            [UIView commitAnimations];
        }

    }

-(void)shrinkTableView
{
    if (searchPanel) {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        objectsTableView.frame = CGRectMake(0, 100, screenRect.size.width, screenRect.size.height -100);
        [UIView commitAnimations];
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top