我的对象上有两个UIImageView,我试图将它们设置为像书一样的页面动画。我用了一段时间的内置动画(UIViewAnimationTransitionFlipFromLeft/Right
),并决定我可以做得更好。我在这里找到了一个很好的动画例子:http://fiftysixtysoftware.com/blog/2009/uiview-pageopen-sample-project/CABasicAnimation CALayer转换的可见性(重叠)问题
我能够从那里推断出我的动画效果......但是我遇到的问题是我的动画图像(正确的图像)总是在下面显示左边的图像。
这里是在初始化代码:
// 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];
事情我已经试过:(你可以看到无论是在上面的代码中)
- bringSubviewToFront/sendSubviewToBac ķ
- 提前任何建议或智慧的层上设置Z指数
感谢。同样,问题是我的imageLeft总是显示在动画之上。
任何人现在看这个问题(超过两年后)应该看看页面视图控制器('UIPageViewController')和它的动画。 – livingtech