How can I enable implicit UIView animation?

吃可爱长大的小学妹 提交于 2019-12-02 22:31:20

问题


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

 _________
|Parent   |
|         |
|         |
|  _____  |  _____
| |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.

I tried something like the following:

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

but the property updated immediately with no animation.

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).

My question:

  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?

回答1:


You can use animateWithDuration:

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


来源:https://stackoverflow.com/questions/9753993/how-can-i-enable-implicit-uiview-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!