У меня есть два UIImageViews на моем объекте, и я пытаюсь оживить их на странице, как книгу. Я использовал некоторые из встроенных анимаций некоторое время (UIViewAnimationTransitionFlipFromLeft/Right
) и решил, что смогу сделать лучше. Я нашел хороший пример для половины анимации, которую я хотел здесь: http://fiftysixtysoftware.com/blog/2009/uiview-pageopen-sample-project/проблемы с видимостью (перекрывающиеся) с CABasicAnimation CALayer преобразования
Мне удалось экстраполировать оттуда, чтобы заставить мою анимацию работать ... но проблема, с которой я сталкиваюсь, заключается в том, что мое анимационное изображение (правильное изображение) всегда отображается внизу левое изображение.
Вот код в 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];
Вещи, которые я пробовал: (вы можете увидеть, как в приведенном выше коде)
- bringSubviewToFront/sendSubviewToBac К
- задания индекса Z на слое
Заранее спасибо за любые советы или мудрости. Опять же, проблема заключается в том, что мой imageLeft всегда отображается поверх анимации.
Любой, кто сейчас смотрит на этот вопрос (более двух лет спустя), должен заглянуть в контроллер просмотра страниц ('UIPageViewController') и его анимацию. – livingtech