0

私はiOSゲームを開発しており、カスタムアニメーションが必要なので、この方法を使用しています

    CGRect basketTopFrame = mainScreenView.frame;
basketTopFrame.origin.x = 320;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.frame = basketTopFrame;
[UIView commitAnimations];

.h ファイルで、このように mainScreen を宣言しました

IBOutlet UIView *mainScreenView;

そのため、IB では UIView をインターフェイスのビューに配置し、mainScreenView に接続しました。

そのため、mainViewScreen では、ビューが表示される場合と表示されない場合があります (2 回目の試行で動作します) が、アニメーション コードを削除すると完全に正常に動作します..何が起こっているのかわかりません。

編集これが私がビューを追加した方法です

MainScreen *mainScreen = [[MainScreen alloc]initWithNibName:@"MainScreen" bundle:nil];
[mainScreenView addSubview:mainScreen.view];
4

2 に答える 2

0

I tried it in a sandbox project, and this worked for me:

- (IBAction)buttonTouched:(id)sender {
    myView.transform = CGAffineTransformMakeTranslation(-320, 0);

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myView.transform = CGAffineTransformMakeTranslation(0,0);
    [UIView commitAnimations];

}
于 2012-05-26T07:42:16.587 に答える
0

何かを画面外に移動しようとしているようです。もっと簡単な方法はこれを行うことです

[UIView beginAnimations:@"UIBase Hide" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.transform = CGAffineTransformMakeTranslation(320,0); //slide view to the right. 
[UIView commitAnimations];

注: Translation で 320 を使用しても、ビューが画面の 320 ピクセル目に移動するのではなく、ビューが 320 ピクセル右に移動します。したがって、mainScreenView が origin.x = 100 にある場合、この変換後は 420 になります。

元に戻すには

 self.transform = CGAffineTransformIdentity;
于 2012-05-26T06:55:18.997 に答える