我有以下视图层次结构
的UITabBarController - UINavigationController - UITableViewController
当表格视图出现(动画)时,我创建了一个工具栏并将其添加为页面底部TabBar的子视图 并让它使用表格视图进行动画处理。当表视图消失时,在其他方向上的过程相同。
它没有按预期工作。
它出了什么问题?
- (void)animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[toolBar removeFromSuperview];
}
- (void)viewWillAppear:(BOOL)animated
{
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 44, 0);
[[self tableView] setContentInset:insets];
[[self tableView] setScrollIndicatorInsets:insets];
// Toolbar initially placed outside of the visible frame (x=320)
UIView *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(320, 480-44, 320, 44)];
[toolBar setTag:1000];
[[[self tabBarController] view] addSubview:toolBar];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[toolBar setFrame:CGRectMake(0, 480-44, 320, 44)];
[UIView commitAnimations];
[toolBar release];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];
[toolBar setFrame:CGRectMake(320, 480-44, 320, 44)];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
答案 0 :(得分:0)
您是否尝试过仅使用表格视图控制器的toolbarItems
属性? UINavigationController
将为您管理工具栏,使用当前最顶层视图控制器的工具栏项更新它;使用-setToolbarHidden:animated:
和-viewWillAppear:
中的-viewWillDisappear:
方法来控制该工具栏的可见性。