2012-03-30 7 views
31

iPhoneアプリの画像を表示するのではなく、画面に「ポップイン」したいと考えています。 「ポップイン」とは、小さなドットから実際のサイズに拡大することを意味します。参考までに、これはKeynoteの "pop"アニメーション効果とまったく同じです。 私はiOSアニメーションを全く新しくしています。もし私が使用する必要のあるアニメーション効果の方向性を指摘できれば、それは大変ありがたいです。iOS - アニメーションエフェクト - 画像ポップアップ

おかげ

ブライアン

UPDATE 私は以下の提案から、このコードを追加しました。これは動作しますが、画像を拡大するのではなく、拡大縮小します。私はそれが変換スケールのサイズとして0.01を持っていることを知っていますが、私はどのように私はサイズ0.0の画像で始めることができますし、1に拡大することができます知っていると思います。 0? おかげ

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration: 0.2]; 
image.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

答えて

78

あなたが探している効果は、このようなものです:あなた場合

// instantaneously make the image view small (scaled to 1% of its actual size) 
view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    // animate it to the identity transform (100% scale) 
    view.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
    // if you want to do something once the animation finishes, put it here 
}]; 
+1

センターと異なるポイントから画像をスケールアップする方法はありますか? – tiguero

+5

はい、レイヤの[アンカーポイント]を変更します(http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/c_ref/CALayer) 。 'theView。layer.anchorPoint = CGPointMake(0、0) 'は、左上からビューの縮尺を変更します。 '(1,1)'はその右下です。 –

+0

可変画像はどのような種類のオブジェクトですか? –

0

あなたが最終状態にゼロからそれを縮小するために、ビューのフレームをアニメーション化する必要があります。 これは、たとえばUIViewのブロックアニメーションで行うことができます。

たとえば、最終的なサイズと位置でIBOutletプロパティself.myViewとしてビューを開始し、隠しフラグを設定します。 そして、あなたはそれには、次の使用を表示したいとき:

// Save old frame as final stater and set it to zero size for the start of the animation 
// But keep the same center position, so it just grows and don't move around 
CGRect oldFrame = self.myView.frame; 
CGRect oldCenter = self.myView.center; 

self.myView.frame = CGRectZero; 
self.myView.center = oldCenter; 

self.myView.hidden = NO; 

NSTimeInterval duration = 0.3; 

[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
       // New position and size after the animation should be the same as in Interface Builder 
       self.myView.frame = oldFrame 
    } 
        completion:^(BOOL finished){ 
               // You can do some stuff here after the animation finished 
        }]; 
+0

これはおそらくうまくいかないでしょう。画像ビューのフレームをアニメートすると、アニメーションのすべてのフレームでそのフレームが再描画されます。 –

+1

@NoahWitherspoonは変換が良い方法でしょうか? – Thyraz

+0

はい。 CGAffineTransformMakeScale(0.01,0.01)からCGAffineTransformIdentityにアニメートすると、このトリックが実行されます。 –

0

スウィフト2.0バージョン

view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in 
     // animate it to the identity transform (100% scale) 
     self.view.transform = CGAffineTransformIdentity; 

     }) { (finished) -> Void in 
     // if you want to do something once the animation finishes, put it here 
    } 
4

〜のようなものがありますFacebookこれは好きなように投稿していますか?

ビュー

をアニメーション化するとき

-(void)animateButton:(UIButton *)sender{ 
UIButton * btn = (UIButton *)sender; 
[UIView animateWithDuration:0.3/1.5 animations:^{ 
    btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3/2 animations:^{ 
     btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button 
     }]; 
    }]; 
}];} 

はちょうどあなたがボタンの上にテキストやイメージを持っているし、あなただけのボタンの画像をアニメーション化したいならば、単にBTN」と「BTN」を置き換える、このメソッドを呼び出します。これは、ボタンの画像ビュープロパティでアニメーションを生成するだけです。 希望に役立つ すべてのベスト。

0

単純なUIViewを使用する必要があります。

現在のビューにUIviewを追加します。

- (void) initPopUpView 
{ 
    popup.alpha = 0; 
    popup.frame = CGRectMake (160, 240, 0, 0); 
    [self.view addSubview:popup]; 
} 

- (void) animatePopUpShow 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationWillStartSelector:@selector(initPopUpView)]; 

    popup.alpha = 1; 
    popup.frame = CGRectMake (20, 40, 300, 400); 

    [UIView commitAnimations]; 
} 
関連する問題