开发者

How can I animate a view sliding from under the nav bar on iPhone?

开发者 https://www.devze.com 2022-12-09 01:40 出处:网络
This is related to my last question. I have an application that I created from the \"Navigation-based application\" template in Xcode. (I have a UINavigationController with a UITableViewController su

This is related to my last question.

I have an application that I created from the "Navigation-based application" template in Xcode. (I have a UINavigationController with a UITableViewController subclass named RootViewController.)

The table shows a list of strings the user can interact with. The nav bar has the standard Edit/Done button on the left, and a Plus-sign button on the right. I would like to slide a view loaded from a .xib file from under the nav bar when the user touches the plus button.

I attempted to implement it by doing the following:

NSArray *xibContents = [[NSBundle mainBundle] loadNibNamed:@"NewNameView" owner:self options:nil];
UIView *view = [xibContents objectAtIndex:0];
[self.view addSubview:view];
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y - 44, view.frame.size.width, view.frame.size.height);
[UIView beginAnimations:@"openAdd" context:nil];
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + 44, view.frame.size.width, view.frame.size.height);
[UIView commitAnimations];

(The height of the view is 44 pixels.) This animates the view sliding down, but开发者_运维百科 it covers the first table cell. I'd like for the table view to slide down as well.


The best way to do this to use directly UITableView methods.

//Update your data model with the new row

[self.tableView beginUpdates];

NSArray* indexPaths = [[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
[indexPaths release];

[self.tableView endUpdates];

Your new row will looks like it would come from under the Navigation bar.

For more info on batch insert/deleting of row and sections.

0

精彩评论

暂无评论...
验证码 换一张
取 消