【问题标题】:How Can i animate two UIView reisizes at once?如何一次为两个 UIView 调整大小设置动画?
【发布时间】:2010-11-28 13:19:31
【问题描述】:

我正在使用此代码:

   [UIView beginAnimations:nil context:NULL];  
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(_shrinkDidEnd:finished:contextInfo:)];
   tblSimpleTable.frame = tableFrame;  
   messegeField.frame = messegeFrame;
   [UIView commitAnimations];

messegeFrame 和 tableFrame 是这个视图的新框架。 我希望这会使表格和消息字段一起移动,但首先表格移动,然后才是消息字段。 有没有办法让它们一起移动?

注意:问题是它们都在调整大小,但不是在同一时间

【问题讨论】:

  • 不,不是,他们不会一起移动

标签: iphone objective-c cocoa-touch uiview uikit


【解决方案1】:

尝试在动画上设置一个计时器,我同时移动了几十个视图,这是您的代码中明显的缺失:

[UIView beginAnimations:nil context:NULL];  

[UIView setAnimationDuration:0.3];

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(_shrinkDidEnd:finished:contextInfo:)];
tblSimpleTable.frame = tableFrame;  
messegeField.frame = messegeFrame;
[UIView commitAnimations];

我也不认为我没有使用 setAnimationDidStopSelector,所以如果这是您的问题,您可以调用动画的结束,并将 NSTimer 设置为与动画相同的时间长度。

【讨论】:

    【解决方案2】:

    从表面上看,这段代码看起来没问题,我之前曾使用这种方法一次翻译多个对象。

    如果您只是移动这 2 个对象,您可以尝试其他替代方法:UIOBJECT.center - 尽管这会间接影响框架。或者使用CGAffineTransformTranslate 过度杀伤力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多