【发布时间】:2012-03-30 22:26:38
【问题描述】:
我想用给定的CAAnimation 为UIView 制作动画,并在动画制作时与视图交互(视图有一个手势识别器)。
如果我理解正确CAAnimation 只会为视图的图层设置动画,但视图本身将保持在原始位置。
如何使UIView 与CAAnimation 一起移动?
【问题讨论】:
标签: iphone ios animation uiview core-animation
我想用给定的CAAnimation 为UIView 制作动画,并在动画制作时与视图交互(视图有一个手势识别器)。
如果我理解正确CAAnimation 只会为视图的图层设置动画,但视图本身将保持在原始位置。
如何使UIView 与CAAnimation 一起移动?
【问题讨论】:
标签: iphone ios animation uiview core-animation
您可以扩展UIView 以覆盖您想要接收触摸的区域,而不是尝试移动它,然后在其中设置layer 的动画。确保将视图opaque 属性设置为NO。
您可能希望将sublayer 添加到view.layer 而不是移动视图自己的图层,例如,如果您希望图层超出视图边界而不影响视图子视图的布局。
【讨论】:
如果您只关心视觉“粘性”,您可以这样做:
[myAnimation setRemovedOnCompletion:NO];
但这只是视觉上的。它不会改变实际图层的属性。
如果您希望图层的属性也更新为新值,您可以执行以下操作:
// You have code above that to register the property you want to animate...
[myAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
[myAnimation setToValue:[NSNumber numberWithFloat:1.0f]];
【讨论】: