【问题标题】:iPhone: Animating a view when another view appears/disappearsiPhone:当另一个视图出现/消失时动画视图
【发布时间】:2010-03-16 16:39:51
【问题描述】:

我有以下视图层次结构

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];
}

【问题讨论】:

    标签: iphone core-animation


    【解决方案1】:

    您是否尝试过仅使用表格视图控制器的toolbarItems 属性? UINavigationController 将为您管理一个工具栏,并使用其当前最顶层视图控制器的工具栏项对其进行更新;在-viewWillAppear:-viewWillDisappear: 中使用-setToolbarHidden:animated: 方法来控制该工具栏的可见性。

    【讨论】:

    • 你是说导航控制器的工具栏吧?我需要表格底部的另一个工具栏,但在上下滚动时它不应该与表格内容一起移动。在上面的代码中,我对动画进行了一些实验,但工具栏只有在表格进入编辑模式时才会可见。嗯...再次将 UIViewController 作为 UITableViewController 的“容器”可能是一个解决方案。
    • 好的,使用简单的 UIViewController 而不是 UITableViewController 解决了这个问题。它的工作原理类似于以下示例:iphonedevelopment.blogspot.com/2008/10/…
    猜你喜欢
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多