【问题标题】:Animate resizing of UIViewControllerUIViewController 的动画调整大小
【发布时间】:2018-04-03 19:56:30
【问题描述】:

在我的应用程序中,我正在尝试构建一个动画,在收到通知时调整 UIViewController 的大小。

我创建了一个容器UIViewController 来封装孩子。然后我写了下面的代码来调整孩子UIViewController的大小。

[UIView animateKeyframesWithDuration:0.5
                               delay:0
                             options:0
                          animations:^{
                              [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
                                  for(int i = 0; i < [self.viewControllers count]; i++) {
                                      UIViewController *vc = [self.viewControllers objectAtIndex:i];
                                      vc.view.frame = CGRectMake(0, [self topOffset], self.view.frame.size.width, self.view.frame.size.height-[self topOffset]);
                                  }
                              }];
                          } completion:^(BOOL finished) {

                          }];

但是,现在发生的情况是立即执行高度更改并且 y 更改是动画的,使得视图看起来像是在向下滑动。关于我可以改变什么以使其调整大小的任何想法?

【问题讨论】:

  • 不要为frame 设置动画,而是尝试同时为boundscenter 设置动画,看看是否会有所不同。

标签: ios objective-c uiviewcontroller uikit


【解决方案1】:

在动画之前所有的 VC 必须有一个帧

 for(int i = 0; i < [self.viewControllers count]; i++) {
   UIViewController *vc =   [self.viewControllers objectAtIndex:i];
   vc.view.frame =  self.view.frame;

 }
[UIView animateKeyframesWithDuration:0.5
                               delay:0
                             options:0
                          animations:^{
                              [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
                                  for(int i = 0; i < [self.viewControllers count]; i++) {
                                      UIViewController *vc = [self.viewControllers objectAtIndex:i];
                                      vc.view.frame = CGRectMake(0, [self topOffset], self.view.frame.size.width, self.view.frame.size.height-[self topOffset]);
                                  }
                              }];
                          } completion:^(BOOL finished) {

                          }];

高度也必须这样计算

 self.view.frame.size.height - 2 * [self topOffset]

如果你想从底部到向上的距离相同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多