簡體   English   中英

UIVIew翻轉垂直動畫

[英]UIVIew Flip Vertical Animation

鑒於:

[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]

通過翻轉動畫“myPic”從右向左動畫。

我需要獲得相同的動畫,但是垂直。 從頂部翻轉或從底部翻轉。 我環顧四周,沒有人真的有建議的工作模型。

我試過這個,但沒有運氣:

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]

有什么輸入? 提前致謝。

我還需要從底部動畫翻轉。 我已經編譯了幾個解決方案,這對我有用

- (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];
                     }];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM