2011-02-28 85 views
4

考慮:UIView的垂直翻轉動畫

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

任何輸入? 在此先感謝。

+0

您應該編輯此問題以使用代碼的「代碼」佈局,以便它實際上可讀。 – PengOne 2011-02-28 16:12:28

+0

對不起。只是改變了它。 – Gizmodo 2011-02-28 16:14:47

+0

定義「沒有運氣」。當你運行這段代碼時會發生什麼? – occulus 2011-02-28 17:19:53

回答

7

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

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

這對我來說幾乎適用。但是,啓動UIView的上半部分以及進入視圖的新UIView在動畫開始時完全不可見。有沒有我需要在這些視圖上設置的定位點值,以便它們的上半部分不會被裁剪? – idStar 2012-04-12 21:16:58