use*_*717 1 core-animation ios
我想将一个视图从一个位置动态移动到一个新的位置.如果更新视图的图层位置,我认为视图将动画移动到新位置,implicit animation我猜,但是没有动画,为什么?
- (IBAction)startAnimation:(id)sender {
CGPoint position = self.imageView.layer.position;
position.y += 90;
self.imageView.layer.position = position;
}
Run Code Online (Sandbox Code Playgroud)
隐式动画仅发生在独立图层上,而不是备份视图的图层.您需要明确动画该位置.您可以通过为位置创建CABasicAnimation并将其添加到图层或使用UIView动画为视图的center属性设置动画来实现.
CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"position"];
move.toValue = [NSValue valueWithCGPoint:newPoint];
move.duration = 0.3;
[self.imageView.layer addAnimation:move forKey:@"myMoveAnimation"];
Run Code Online (Sandbox Code Playgroud)
[UIView animateWithDuration:0.3 animations:^{
self.imageView.center = newCenter;
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4300 次 |
| 最近记录: |