(Core)animation开始时,图层位置跳转

所以,我试图创build一个平铺翻转效果,就像在Windows Phone 7上一样。

到目前为止,我有以下代码,但我有几个查询。

CALayer *layer = self.theRedSquare.layer; CATransform3D initialTransform = self.theRedSquare.layer.transform; initialTransform.m34 = 1.0 / -1000; [UIView beginAnimations:@"Scale" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; layer.transform = initialTransform; layer.anchorPoint = CGPointMake(-0.3, 0.5); CATransform3D rotationAndPerspectiveTransform = self.theRedSquare.layer.transform; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -self.theRedSquare.bounds.size.height/2, 0); layer.transform = rotationAndPerspectiveTransform; [UIView setAnimationDelegate:self]; [UIView commitAnimations]; 

1.我的红色方块(简单的用户界面视图)在animation开始时如何转化为右侧?

2.对于定位点,可以在父视图上设置一个位置? 目前,我正在相对于目前的观点任意设定它。

提前感谢任何指针。

animation之前

之前

在animation中(注意广场右移)

中

animation之后(注意广场右移)

后

video添加: 示例video

 -(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view { CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); newPoint = CGPointApplyAffineTransform(newPoint, view.transform); oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); CGPoint position = view.layer.position; position.x -= oldPoint.x; position.x += newPoint.x; position.y -= oldPoint.y; position.y += newPoint.y; view.layer.position = position; view.layer.anchorPoint = anchorPoint; } -(void)animateView:(UIView *)theRedSquare { CALayer *layer = theRedSquare.layer; CATransform3D initialTransform = theRedSquare.layer.transform; initialTransform.m34 = 1.0 / -1000; [self setAnchorPoint:CGPointMake(-0.3, 0.5) forView:theRedSquare]; [UIView beginAnimations:@"Scale" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; layer.transform = initialTransform; CATransform3D rotationAndPerspectiveTransform = theRedSquare.layer.transform; rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -theRedSquare.bounds.size.height/2, 0); layer.transform = rotationAndPerspectiveTransform; [UIView setAnimationDelegate:self]; [UIView commitAnimations]; } 

采取从这,稍微调整..希望它有帮助改变我的CALayer的anchorPoint移动视图

CALayeranchorPoint的可接受范围是[0,1]。 在你的情况下,你试图围绕Y轴翻转,你的图层的锚点应该是[0,0.5]。

如果您将广场视为自己的视angular,则会翻转内置

 [UIView beginAnimations:@"flip" context:nil]; [UIView setAnimationDuration:.35f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES]; // change to the new view (make this one hidden, the other not) [UIView commitAnimations];