animation:如何使用图层来animation视图?

图像显示我想实现的

我想dynamic地从一个位置移动到一个新的位置。 如果更新视图的图层位置,我认为视图会animation地移动到新的位置,这是我猜的implicit animation ,但是没有animation,为什么?

 - (IBAction)startAnimation:(id)sender { CGPoint position = self.imageView.layer.position; position.y += 90; self.imageView.layer.position = position; } 

隐式animation只发生在独立层上,而不是备份视图的层。 您将需要明确地animation位置。 您可以通过为位置创buildCABasicAnimation并将其添加到图层或使用UIViewanimation来为视图的中心属性设置animation。

创build一个明确的animation

 CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"position"]; move.toValue = [NSValue valueWithCGPoint:newPoint]; move.duration = 0.3; [self.imageView.layer addAnimation:move forKey:@"myMoveAnimation"]; 

使用UIViewanimation

 [UIView animateWithDuration:0.3 animations:^{ self.imageView.center = newCenter; }];