1

내 개체에 두 개의 UIImageViews가 있고 책처럼 페이지를 움직이기 위해 노력하고 있습니다. 나는 내장 애니메이션의 일부를 잠시 사용했고 (UIViewAnimationTransitionFlipFromLeft/Right), 나는 더 잘할 수있을 것이라고 결정했다.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 어떤 조언이나 지혜를 사전에 레이어에

감사를 A ~ Z 인덱스를 설정

  • 케이. 다시 말하지만 문제는 내 imageLeft가 항상 애니메이션 상단에 표시되는 것입니다.

  • +0

    2 년이 지난 지금이 ​​질문을 보는 사람은 누구나 페이지 뷰 컨트롤러 ('UIPageViewController')를 살펴보고 애니메이션을 사용해야합니다. – livingtech

    답변

    2

    나는 같은 문제에 직면했으며보기의 z 위치를 설정하여 문제를 해결할 수 있다는 것을 알았습니다. 다음과 같이 사용했습니다.

    viewThatShouldBeSentToTheBack.layer.zPosition = -10000;

    0

    내가 애니메이션보기를 전면에 가져 오면 모든 것이 효과가 있다는 것을 발견했습니다. 저는 페이지 넘기기 애니메이션을 작업 중이며, 페이지 오버레이를 시계 반대 방향으로 보여주기 위해 뒤로 페이징 할 때 문제가있었습니다. 내 문제는 오버레이 할 것으로 예상되는 페이지 뒤에 있기 때문에 애니메이션을 볼 수 없다는 것이 었습니다.

    +0

    내 문제의 핵심은 bringSubviewToFront가 나를 위해 아무 것도하지 않는다는 것입니다. – livingtech

    0

    페이지 뷰를 수퍼 뷰에 추가 할 때 배열을 올바르게 반복하고 있습니까? 당연히, 마지막 페이지를 맨 아래에 놓고 첫 페이지를 맨 위에 놓고 싶습니다 ... 나는 당신의 지성을 모욕하는 것이 아닙니다. 레이어가 까다로울 수 있습니다.

    +0

    나는 어떤 시점에서 하위 뷰를 반복하지 않고있다. 여기서 사용 된 애니메이션은 레이어에만 적용될 수 있다는 점에서 흥미로운 이분법이 있습니다. 그러나 다른 방법으로는 부모에게 이미 추가 된보기로 작업하고있었습니다. – livingtech

    0

    나는이 정확한 문제를 겪었고 피할 수있는 유일한 방법은 tyhe 배경의 zPosition을 큰 음수로 설정하는 것입니다. 이유를 정확히 아는 것이 좋을 것입니다 ...