2

を使用してUIImageView、静止画像とアニメーション画像の両方を表示しています。だから時々、私は使用 .imageして.animationImagesいます。これで問題ありません。

静的であろうとアニメーションであろうと、私は を格納しUIImagesますitem.frames(以下を参照)

UIActivityIndicatorView問題は、アニメーション フレームの読み込み中にビューの中央にa を表示したいということです。画像やフレームを入れずにこれを実現したいと思います。本来の動作をしていない行は次のとおりです。

[self.imageView removeFromSuperview];

実際のところ、この時点で別の画像に設定しても何も起こりません。ここでは UI の処理は行われていないようです。ところで、

NSLog(@"%@", [NSThread isMainThread]?@"IS MAIN":@"IS NOT");

印刷しIS MAINます。

そこにある画像は、新しいアニメーション フレームがすべてそこにある (1 ~ 2 秒) まで残り、アニメーションが開始されます。

これはすべて、UIImageView をサブビューとして UIView のサブクラスから実行されています。

- (void)loadItem:(StructuresItem *)item{

    self.imageView.animationImages = nil;
    self.imageView.image = nil;   

    [self.spinner startAnimating];

    self.item = item;

    if (item.frameCount.intValue ==1){
        self.imageView.image = [item.frames objectAtIndex:0];
        self.imageView.animationImages = nil;
    }else {
        [self.imageView removeFromSuperview];

        self.imageView =[[UIImageView alloc] initWithFrame:self.bounds];
        [self addSubview:self.imageView ];
        if( self.imageView.isAnimating){
            [self.imageView stopAnimating];
        }
        self.imageView.animationImages = item.frames;
        self.imageView.animationDuration = self.imageView.animationImages.count/12.0f;

        //if the image doesn't loop, freeze it at the end
        if (!item.loop){
            self.imageView.image = [self.imageView.animationImages lastObject];
            self.imageView.animationRepeatCount = 1;
        }
        [self.imageView startAnimating];
    }

    [self.spinner stopAnimating];

}

私の無知な評価は、その画像が nil に設定されると、何かが再描画されていないということです。手が大好きです。

4

1 に答える 1

1

私が見つけたのは、質問に対する答えではなく、問題に対するより良いアプローチです。簡単に言えば、animationImages の代わりに NSTimer を使用してください。ロードがはるかに高速で、メモリを使い果たしず、コードが単純です。わーい!

これを行う:

-(void)stepFrame{
    self.currentFrameIndex =   (self.currentFrameIndex + 1) % self.item.frames.count;
    self.imageView.image = [self.item.frames objectAtIndex:self.currentFrameIndex];
}

この

-(void)run{
    if (self.item.frameCount.intValue>1){
        self.imageView.image = [self.item.frames objectAtIndex:self.currentFrameIndex];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:1/24.0f target:self selector:@selector(stepFrame) userInfo:nil repeats:YES];
    }else{
        self.imageView.image = [self.item.frames objectAtIndex:0];
    }
}
于 2012-08-21T15:56:15.107 に答える