【问题标题】:how to animate uitoolbar如何为 uitoolbar 设置动画
【发布时间】:2012-01-08 16:42:25
【问题描述】:

我正在尝试为我的 uitoolbar 设置动画。我正在尝试扩展和收缩我的 uiview。我希望工具栏与视图一起动画。但是这里的 uitoolbar 先扩展和收缩,然后 uiview 开始动画。所以 uitoolbar 框架会根据矩形变化,但它没有动画。有人可以告诉我如何为 uitoolbar 设置动画。除了工具栏,我还想为标签栏设置动画。我该怎么做呢。

在我看来,我编写了以下代码:

 [UIView animateWithDuration:1.0 animations:^(void){

        [recordDetailView setFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, recordDetailView.frame.size.height)];
        [normalModeToolbar setFrame:CGRectMake(0.0, 0.0,self.view.frame.size.width, 49)];
        [self.view bringSubviewToFront:recordDetailView];
    } completion:^(BOOL finished){
    }
     ];

【问题讨论】:

    标签: iphone ios uiview uitabbar uitoolbar


    【解决方案1】:

    UIViewAnimationOptionLayoutSubviews (iOS > 4.0) 应该可以解决大小变化没有动画化时的问题。

    [UIView animateWithDuration:1.0 
            delay:0 
            options:UIViewAnimationOptionLayoutSubviews 
            animations:^{
               [recordDetailView setFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,                 recordDetailView.frame.size.height)];
               [normalModeToolbar setFrame:CGRectMake(0.0, 0.0,self.view.frame.size.width, 49)];
           }
            completion:nil
    ];
    

    【讨论】:

      【解决方案2】:

      您是否尝试过使用边界?

      [UIView animateWithDuration:1.0 animations:^(void){
          yourView.bounds = CGRectMake(yourView.bounds.origin.x, 
                                       yourView.bounds.origin.y, 
                                       yourView.bounds.size.width * 2, // target width 
                                       yourView.bounds.size.height);
      }];
      

      此外,我还会尝试在开始动画之前将您的 recordDetailView 放在前面。

      【讨论】:

      • 帧是动画的。您对 CALayer 和 UIView 类感到困惑。
      • 啊,谢谢你的提示!那么,如何了解 UIView 的动画属性呢?
      • @zlajo :我的视图动画正确。但我想为工具栏设置动画。工具栏改变了它的框架,但没有动画。你能告诉我为什么工具栏可能没有动画吗???
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多