2012-02-07 10 views
6

の開始時にジャンプし、私は、Windows Phoneのように、タイル反転効果を作成するために、7層位置は、(コア)アニメーションだから、

をしようとしているこれまでのところ、私は次のコードを持っているが、私はのカップルを持っていますクエリ。私の私の赤い四角(シンプルなUIビュー)は、アニメーションの開始時に右に変換する方法来る

CALayer *layer = self.theRedSquare.layer; 
CATransform3D initialTransform = self.theRedSquare.layer.transform; 
initialTransform.m34 = 1.0/-1000; 

[UIView beginAnimations:@"Scale" context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
layer.transform = initialTransform; 
layer.anchorPoint = CGPointMake(-0.3, 0.5); 

CATransform3D rotationAndPerspectiveTransform = self.theRedSquare.layer.transform; 

rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -self.theRedSquare.bounds.size.height/2, 0); 

layer.transform = rotationAndPerspectiveTransform; 

[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

1.?

2.親ビューの位置を設定することは可能ですか?現時点では、私はそれを現在のビューに相対して任意に設定しています。

ありがとうございます。アニメーション中アニメーション

Before

(正方形が右にシフトしている気づく)

During

アニメーション後(正方形を通知は右にシフトしています)

After

ビデオが追加されました:example video

答えて

6
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view 
{ 
    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); 
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); 

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform); 
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); 

    CGPoint position = view.layer.position; 

    position.x -= oldPoint.x; 
    position.x += newPoint.x; 

    position.y -= oldPoint.y; 
    position.y += newPoint.y; 

    view.layer.position = position; 
    view.layer.anchorPoint = anchorPoint; 
} 

-(void)animateView:(UIView *)theRedSquare 
{ 
    CALayer *layer = theRedSquare.layer; 
    CATransform3D initialTransform = theRedSquare.layer.transform; 
    initialTransform.m34 = 1.0/-1000; 

    [self setAnchorPoint:CGPointMake(-0.3, 0.5) forView:theRedSquare]; 


    [UIView beginAnimations:@"Scale" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    layer.transform = initialTransform; 


    CATransform3D rotationAndPerspectiveTransform = theRedSquare.layer.transform; 

    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -theRedSquare.bounds.size.height/2, 0); 

    layer.transform = rotationAndPerspectiveTransform; 

    [UIView setAnimationDelegate:self]; 
    [UIView commitAnimations]; 
} 

これから撮影、そして少し微調整...うまくいけば、それは Changing my CALayer's anchorPoint moves the view

+0

すばらしい、ありがとう! – JonB

+0

アニメーションをアニメーション化するにはどうすればよいですか? (そのフリップイン)私はこれを理解するために何時間も試みてきました。 – Frankrockz

2

CALayeranchorPointの許容範囲は[0,1]です。あなたの場合、Y軸の周りを反転しようとしているところで、レイヤーのアンカーポイントは[0、0.5]にする必要があります。あなたは正方形の独自のビューを作成する場合

+0

に役立ちます私はこの作業の罰金を持っていました赤のUIViewはアニメーションを開始する前に右にシフトします。私はビデオをしようとします。興味深いことに、anchorPointの-0.3は、y軸のオフセットを中心に左に回転します。 – JonB

+0

に問題を示す動画が追加されました。アニメーションの最初の実行では、正方形は右のピクセル数だけシフトします。それを動作させるように見えることはできません。 – JonB

3

、反転が内蔵されている

[UIView beginAnimations:@"flip" context:nil]; 
[UIView setAnimationDuration:.35f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft 
    forView:self.window cache:YES]; 

// change to the new view (make this one hidden, the other not) 

[UIView commitAnimations]; 
+0

私の説明からあまりにも明白ではなかったことを認めていますが、私はその場からひっくり返ったわけではありません。私は赤い四角形(これはすでにUIViewです)の左端を回りたいです。私が後にしている効果の種類から、次のビデオを参照してください:http://www.youtube.com/watch?v=wgoGDPF_NGo – JonB

関連する問題