如何启用隐式UIView动画? [英] How can I enable implicit UIView animation?

查看:336
本文介绍了如何启用隐式UIView动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在这里围绕动画包裹我的大脑。这是我的基本情况:

Trying to wrap my brain around animations here. Here is my basic situation:

 _________
|Parent   |
|         |
|         |
|  _____  |  _____
| |A    | | |B    |
| |_____| | |_____|
|_________|

其中是父视图和 A B 都是 UIView 个实例。我选择了 A B UIView s因为,据我了解,图层无法接收用户交互。我想做的动画非常简单:我只想要 A 向左滑动,而 B 幻灯片从右边开始。

where Parent is the parent view and A and B are both UIView instances. I chose to make A and B UIViews because, as I understand it, layers cannot receive user interaction. The animation I want to do is very simple: I simply want A to slide offscreen to the left while B slides in from the right.

我尝试过以下内容:

CALayer *layer = viewA.layer;
layer.position = CGPointMake(initialLayer.position.x, initialLayer.position.y - 480);

但该属性立即更新,没有动画。

but the property updated immediately with no animation.

我能够毫不费力地使用 CABasicAnimation 来解决这个问题,但是我想学习使用隐式动画来实现这种场景,这样我就可以更快地进行原型设计在将来。 这篇文章似乎暗示 UIView s无法执行隐含动画(至少在默认情况下)。

I was able to get this working using CABasicAnimation without too much trouble, but I want to learn to use implicit animations for this kind of scenario so I can prototype more quickly in the future. This post seems to suggest that UIViews can't perform implicit animation (at least by default).

我的问题:


  1. 有吗一种在 UIView 的图层上隐式动画属性的方法?怎么样?

  2. 如果没有,有没有比我的方法更好/规范的方法呢?

  1. Is there a way to implicitly animate properties on a UIView's layer? How?
  2. If not, is there a better/canonical way to do this that's different from my method?


推荐答案

你可以使用 animateWithDuration

[UIView animateWithDuration:2.0 animations:^{
    viewA.frame = newFrame;
}];

这篇关于如何启用隐式UIView动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆