Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 views
in Technique[技术] by (71.8m points)

iphone - UIVIew Flip Vertical Animation

Given:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:card cache:NO];
 myPic = [UIImage UIImagenamed: @"mySecondImage.png"];
[UIView commitAnimations];[/CODE]

Which animates 'myPic' right to left with a flip.

I need to get the same animation, but vertically. Flip from Top or Flip from Bottom. I looked around, no one really had a working model suggested.

I tried this, yet, no luck:

float duration = .5;
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
animation.fromValue = [NSNumber numberWithDouble:0.0f * M_PI];
animation.toValue = [NSNumber numberWithDouble:1.0f * M_PI];
animation.duration = duration;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
animation.repeatCount =1;;
animation.beginTime = CACurrentMediaTime();
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
card.layer.anchorPoint = CGPointMake(0.5, 1.0);
[card.layer addAnimation:animation forKey:@"rotationX"];[/CODE]

Any input? Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've also needed flip from bottom animation. I've compiled couple solutions and this works for me

- (CATransform3D) makeRotationAndPerspectiveTransform:(CGFloat) angle {
    CATransform3D transform = CATransform3DMakeRotation(angle, 1.0f, 0.0f, 0.0f);
    transform.m34 = 1.0 / -500;
    return transform;
}

- (void) flipFromBottom {

    //setup firstView to be visible
    view1.layer.transform =  CATransform3DMakeRotation(0, 1.0f, 0.0f, 0.0f);
    view1.hidden = NO;

    // setup secondView to be partialy rotated and invisible
    view2.layer.transform = [self makeRotationAndPerspectiveTransform:M_PI/2];
    view2.hidden = YES;

    // making sure that both views have the same position
    view2.frame = view1.frame;

    CFTimeInterval duration =  2.0;

    [UIView animateWithDuration:duration/2 
                          delay:0
                        options:UIViewAnimationCurveEaseIn
                     animations:^{
                         view1.layer.transform = [self makeRotationAndPerspectiveTransform:-M_PI / 2];
                     } 
                     completion:^(BOOL finished){
                         view1.hidden = YES;
                         view2.hidden = NO;
                         [UIView animateWithDuration:duration /2 
                                               delay:0
                                             options:UIViewAnimationCurveEaseOut
                                          animations:^{
                             view2.layer.transform =  CATransform3DMakeRotation(0.0f, 1.0f, 0.0f, 0.0f);
                                          }
                                          completion:NULL];
                     }];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...