1

我的对象上有两个 UIImageViews,我正在尝试将它们设置为像书一样的页面。我使用了一些内置动画一段时间(UIViewAnimationTransitionFlipFromLeft/Right),并决定我可以做得更好。我在这里找到了我想要的一半动画的一个很好的例子:http: //fiftysixtysoftware.com/blog/2009/uiview-pageopen-sample-project/

我能够从那里推断出让我的动画工作......但我遇到的问题是我的动画图像(右图像)总是显示在左图像下方。

这是 init 中的代码:

// set up some rects for use later
landscapeLeftRect = CGRectMake(0, 12, 512, 725);
landscapeRightRect = CGRectMake(512, 12, 512, 725);

// all our images
imageLeft = [[UIImageView alloc] initWithFrame:portraitRect];
imageRight = [[UIImageView alloc] initWithFrame:landscapeRightRect];

...并执行实际动画(请注意,这是动画的后半部分,与我的 imageLeft 视图“重叠”的一半):

// set the image to be nextLeft
//[imageRight setImage:image.nextLeft];
[self.view sendSubviewToBack:imageLeft];
[self.view bringSubviewToFront:imageRight];
//[imageRight.layer setZPosition:1.0f];
[imageRight setFrame:landscapeLeftRect];

// remove any previous animations
[imageRight.layer removeAllAnimations];

// set up the anchorPoint and center
if (imageRight.layer.anchorPoint.x != 1.0f) {
    imageRight.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
    imageRight.center = CGPointMake(imageRight.center.x + imageRight.bounds.size.width/2.0f, imageRight.center.y);
}

// create an animation to hold the first half of the page turning forward
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.removedOnCompletion = YES;
transformAnimation.duration = 0.40f;
transformAnimation.delegate = self;
transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// start the animation from the current state
CATransform3D endTransform = CATransform3DMakeRotation(3.141f/2.0f,
                                                       0.0f,
                                                       -1.0f,
                                                       0.0f);
// these values control the 3D projection outlook
endTransform.m34 = -0.001f;
endTransform.m14 = 0.0015f;
transformAnimation.fromValue = [NSValue valueWithCATransform3D:endTransform];
// we should end up at the beginning...
transformAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];

[imageRight.layer addAnimation:transformAnimation forKey:nil];

我尝试过的事情:(你可以在上面的代码中看到)

  • 将SubviewToFront/sendSubviewToBack
  • 在图层上设置 Z 索引

提前感谢您的任何建议或智慧。同样,问题在于我的 imageLeft 总是显示在动画的顶部。

4

4 回答 4

3

我遇到了同样的问题,只是发现您可以通过设置视图的 zPosition 来解决它。我用过这样的东西:

viewThatShouldBeSentToTheBack.layer.zPosition=-10000;

于 2010-11-21T07:50:18.530 回答
0

我发现一旦我把动画视图放到前面,一切都正常了。我正在制作翻页动画,并且在以逆时针方式向后翻页显示页面覆盖时遇到问题。我的问题是我看不到动画,因为它位于应该覆盖的页面后面。

于 2010-04-20T17:01:54.840 回答
0

在将页面视图添加到超级视图时,您确定您正在正确地遍历数组吗?自然地,你会想把最后一页放在最前面,这样你的第一页就在上面……我不是在侮辱你的智慧——分层可能很棘手。

于 2010-04-22T20:13:57.873 回答
0

我遇到了这个精确的问题,我发现避免它的唯一方法是将背景的 zPosition 设置为一个大的负数。很高兴知道确切的原因……</p>

于 2011-04-28T22:54:38.590 回答