iPhone: contentInset isn't animating

Posted by Cuzog on Stack Overflow See other posts from Stack Overflow or by Cuzog
Published on 2010-06-07T04:40:14Z Indexed on 2010/06/07 4:42 UTC
Read the original article Hit count: 366

In my app, I have a table view. When the user clicks a button, a UIView overlays part of that table view. It's essentially a partial modal. That table view is intentionally still scrollable while that modal is active. To allow the user to scroll to the bottom of the table view, I change the contentInset and scrollIndicatorInsets values to adjust for the smaller area above the modal. When the modal is taken away, I reset those inset values.

The problem is that when the user has scrolled to the bottom of the newly adjusted inset and then dismisses the modal, the table view jumps abruptly to a new scroll position because the inset is changed instantly. I would like to animate it so there is a transition, but the beginAnimation/commitAnimations methods aren't affecting it for some reason.

Any ideas as to why the values aren't getting animated? Any help is greatly appreciated!

The relevant code from the table view controller is here:

- (void)viewDidLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modalOpened) name:@"ModalStartedOpening" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modalDismissed) name:@"ModalStartedClosing" object:nil];
    [super viewDidLoad];
}

- (void)modalOpened {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 201, 0);
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 201, 0);
    [UIView commitAnimations];
}

- (void)modalDismissed {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [UIView commitAnimations];
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa-touch