Iphone 层位置在(核心)动画开始时跳跃

Iphone 层位置在(核心)动画开始时跳跃,iphone,ios,ipad,core-animation,Iphone,Ios,Ipad,Core Animation,所以,我正在尝试创建一个平铺翻转效果,就像在WindowsPhone7上一样 到目前为止,我有以下代码,但我有几个查询 CALayer *layer = self.theRedSquare.layer; CATransform3D initialTransform = self.theRedSquare.layer.transform; initialTransform.m34 = 1.0 / -1000; [UIView beginAnimations:@"Scale" context:ni

所以,我正在尝试创建一个平铺翻转效果,就像在WindowsPhone7上一样

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

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。为什么我的红方块(一个简单的UI视图)会在动画开始时转换为右侧?

2。对于定位点,是否可以在父视图上设置位置?目前,我正在相对于当前视图任意设置它。

提前感谢您的指点

动画之前

在动画期间(请注意,方形已向右移动)

动画之后(请注意,方形已向右移动)


添加视频:

一个
CALayer
主播点的可接受范围为[0,1]。在您尝试绕Y轴翻转的情况下,层的定位点应为[0,0.5]。

如果将正方形设置为自己的视图,则翻转是内置的

[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];
从这张照片上取下来,稍微调整一下。。希望能有所帮助

我很感激从我的描述来看这不是太明显,但我并不是在从现场翻过来之后。我想翻转我的红方块(已经是UIView)的左边缘。请看下面的视频,了解我想要的效果:我的效果很好,但是红色的UIView甚至在开始动画之前就已经移动了。我会试试看录像。有趣的是-0.3对于anchorPoint工作,它绕y轴向左偏移旋转。我们添加了一个视频来显示问题。在动画的第一次运行中,正方形向右移动若干像素。似乎无法解决这个问题。你如何让动画只是在动画中?(翻过来)我花了几个小时想弄明白。这帮了我:
-(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];
}