2011-03-14 7 views
3

두 개의 뷰 컨트롤러간에 플립 앤 스케일 애니메이션을 만들려고합니다. 이것은 iOS 4.0에서 사용할 수있는 애니메이션 블록을 사용하여 가능할 것으로 보이지만 구현 방법은 여전히 ​​확실하지 않습니다. 플립 애니메이션을 보여주는 this SO 질문을 찾았습니다.iPhone SDK : 블록을 사용하는보기 컨트롤러 사이의 플립 앤 스케일 애니메이션?

이 코드를 사용하면 두보기 사이를 전환해도 문제가 없지만 크기 조정은 수행되지 않습니다. 플립 애니메이션이 완료되고 새보기가 올바른 크기로 이동합니다. 뷰를 플립하고 동시에 크기를 조정하려면 어떻게해야합니까?

UIView *tempContainer = myView.contentView ; 
[UIView transitionWithView:tempContainer 
        duration:2 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       animations:^{ 
        [[[tempContainer subviews] objectAtIndex:0] removeFromSuperview]; 
        [tempContainer addSubview:myOtherViewController.view]; 
        CGAffineTransform transform = CGAffineTransformMakeScale(4.0, 4.0); 
        tempContainer.transform = transform; 
       } 
       completion:^(BOOL finished){ 
        [tempContainer release]; 
       }]; 
+0

나는이 [link] (http://stackoverflow.com/a/5640238/751026)가 도움이 될 것이라고 확신한다. – thesummersign

답변

0

UIViewAnimationOptionTransitionFlipFromRight 옵션이 어떻게 든 다른 것보다 우선하므로이 문제가 발생할 것으로 생각됩니다. 사용해보십시오 nesting animations 또는 link them together

0

다음은 서로 다른 크기의 두보기 사이를 전환하는 방법입니다. 나는 애니메이션을 몇 부분으로 나누었다. 처음에는 백 뷰를 정면 뷰와 같은 위치에 놓았지만 숨겨 둡니다. 그런 다음 정면도를 반쯤 뒤집습니다. 후면보기에는 정면보기와 동일한 변형이 주어지며 나머지는 회전되고 크기가 조절됩니다. 뒤집기는 기본적으로 반대입니다.

다른보기 컨트롤러보기 속성을 후면보기로 사용할 수 있다고 생각하지만 시도하지 않았습니다.

// flip and scale frontView to reveal backView to the center of the screen 
// uses a containerView to mark the end of the animation 
// parameterizing the destination is an exercise for the reader 
- (void)flipFromFront:(UIView*)frontView toBack:(UIView*)backView destination:(CGRect)destRect 
{ 
    float duration = 0.5; 

    // distance from center of screen from frontView 
    float dx = destRect.origin.x + CGRectGetWidth(destRect)/2 - frontView.center.x; 
    float dy = destRect.origin.y + CGRectGetHeight(destRect)/2 - frontView.center.y; 
    float scale = CGRectGetWidth(destRect)/CGRectGetWidth(frontView.bounds); 

    // this prevents any tearing 
    backView.layer.zPosition = 200.0; 

    // hide the backView and position where frontView is 
    backView.hidden = NO; 
    backView.alpha = 0.0; 
    backView.frame = frontView.frame; 

    // start the animation 
    [UIView animateKeyframesWithDuration:duration 
            delay:0.25 
           options:UIViewKeyframeAnimationOptionCalculationModeCubic 
           animations:^{ 
            // part 1. Rotate and scale frontView halfWay. 
            [UIView addKeyframeWithRelativeStartTime:0.0 
                  relativeDuration:0.5 
                   animations:^{ 
                    // get the transform for the blue layer 
                    CATransform3D xform = frontView.layer.transform; 
                    // translate half way 
                    xform = CATransform3DTranslate(xform, dx/2, dy/2, 0); 
                    // rotate half way 
                    xform = CATransform3DRotate(xform, M_PI_2, 0, 1, 0); 
                    // scale half way 
                    xform = CATransform3DScale(xform, scale/2, scale/2, 1); 
                    // apply the transform 
                    frontView.layer.transform = xform; 
                   }]; 

            // part 2. set the backView transform to frontView so they are in the same 
            // position. 
            [UIView addKeyframeWithRelativeStartTime:0.5 
                  relativeDuration:0.0 
                   animations:^{ 
                    backView.layer.transform = frontView.layer.transform; 
                    backView.alpha = 1.0; 
                   }]; 

            // part 3. rotate and scale backView into center of container 
            [UIView addKeyframeWithRelativeStartTime:0.5 
                  relativeDuration:0.5 
                   animations:^{ 
                    // undo previous transforms with animation 
                    backView.layer.transform = CATransform3DIdentity; 
                    // animate backView into new location 
                    backView.frame = destRect; 
                   }]; 
           } completion:^(BOOL finished) { 
            self.displayingFront = !self.displayingFront; 
           }]; 
} 

// flip from back to front 
- (void) flipFromBack:(UIView*)backView toFront:(UIView*)frontView 
{ 
    float duration = 0.5; 

    // get distance from center of screen to destination 
    float dx = backView.center.x - frontView.center.x; 
    float dy = backView.center.y - frontView.center.y; 

    backView.layer.zPosition = 200.0; 
    frontView.hidden = YES; 

    // this is basically the reverse of the previous animation 
    [UIView animateKeyframesWithDuration:duration 
            delay:0 
           options:UIViewKeyframeAnimationOptionCalculationModeCubic 
           animations:^{ 
            [UIView addKeyframeWithRelativeStartTime:0.0 
                  relativeDuration:0.5 
                   animations:^{ 
                    CATransform3D xform = backView.layer.transform; 
                    xform = CATransform3DTranslate(xform, -dx/2, -dy/2, 0); 
                    xform = CATransform3DRotate(xform, M_PI_2, 0, 1, 0); 
                    xform = CATransform3DScale(xform, 0.75, 0.75, 1); 
                    backView.layer.transform = xform; 
                   }]; 

            [UIView addKeyframeWithRelativeStartTime:0.5 
                  relativeDuration:0.0 
                   animations:^{ 
                    backView.alpha = 0.0; 
                    frontView.hidden = NO; 
                   }]; 

            [UIView addKeyframeWithRelativeStartTime:0.5 
                  relativeDuration:0.5 
                   animations:^{ 
                    self.hiddenView.alpha = 0.0; 
                    frontView.layer.transform = CATransform3DIdentity; 
                   }]; 
           } completion:^(BOOL finished) { 
            self.displayingFront = !self.displayingFront; 
           }]; 
} 
관련 문제