我的對象上有兩個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