0

私のアプリには、ユーザーがボタンをタップしたときに再生されるアニメーションがあります。ボタンタップのIBActionメソッドでは、NSMutable配列を作成し、画像を配列にロードしてから、画像を循環させています。

これにより、ボタンのタップとアニメーションの再生の間にかなりの遅れが生じますが、配列はすでに画像で作成されているため、その後のすべてのタップは問題ありません。

配列の作成と画像の読み込みをvieDidLoadメソッドに配置しようとしましたが、何らかの理由でIBActionメソッド(画像を循環する呼び出しがあります)が配列にアクセスできません。アレイを利用できるようにするにはどうすればよいですか?

- (IBAction)tap {

NSMutableArray *anim = [[NSMutableArray alloc]initWithObjects:[UIImage      imageNamed:@"0001.png"], ...(x30)... nil];

type.animationImages  = anim;
    type.animationDuration = 1.0;
    type.animationRepeatCount = 1;

    [type startAnimating];

}
4

3 に答える 3

0

NSMutableArray*animを.hファイルまたはクラスメンバー変数で定義します

viewDidLoadメソッドで次のように定義します。

anim = [[NSMutableArray alloc]initWithObjects:[UIImage      imageNamed:@"0001.png"], ...(x30)... nil];

ボタンイベントで次のように使用します。

 - (IBAction)tap 
{
  type.animationImages  = anim;
  type.animationDuration = 1.0;
  type.animationRepeatCount = 1;
  [type startAnimating];
}
于 2012-08-28T06:18:08.340 に答える
0

この単純なコードを試してみてください。アレイは、最初にタップしたときに1回割り当てます。

if(!anim)
{
NSMutableArray *anim = [[NSMutableArray alloc]initWithObjects:[UIImage      imageNamed:@"0001.png"], ...(x30)... nil];

   NSLog(@"array allocate");
}else
    {
       NSLog(@"array already allocated");
     }
于 2012-08-28T06:18:12.783 に答える
0

ファイルに定義NSMutableArray *animしますUIViewController .h。これにより、グローバルでファイルのどこにでもアクセスできるようになり.mます。

- (void) viewDidLoad
{
    anim = [[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"0001.png"], ...(x30)... nil];
}

- (IBAction)tap 
{

    type.animationImages  = anim;
    type.animationDuration = 1.0;
    type.animationRepeatCount = 1;

    [type startAnimating];

}
于 2012-08-28T06:18:54.377 に答える