我如何启用隐式UIViewanimation?
试图把我的大脑围绕animation这里。 这是我的基本情况:
_________ |Parent | | | | | | _____ | _____ | |A | | |B | | |_____| | |_____| |_________|
其中Parent
是父视图, A
和B
都是UIView
实例。 我select制作A
和B
UIView
,因为据我所知,图层不能接收用户交互。 我想要做的animation非常简单:我只想让A
在屏幕左侧滑动,而B
从右侧滑动。
我尝试了以下内容:
CALayer *layer = viewA.layer; layer.position = CGPointMake(initialLayer.position.x, initialLayer.position.y - 480);
但该属性立即更新,没有animation。
使用CABasicAnimation
可以让我的工作没有太多麻烦,但是我想学习使用隐式animation来处理这种场景,所以我可以在未来更快地进行原型devise。 这个post似乎暗示, UIView
不能执行隐式animation(至less默认)。
我的问题:
- 有没有一种方法隐式地在
UIView
的图层上animation的属性? 怎么样? - 如果没有,是否有更好的/规范的方式来做到这一点,这是不同于我的方法?
你可以使用animateWithDuration
:
[UIView animateWithDuration:2.0 animations:^{ viewA.frame = newFrame; }];