1

ビューの 1 つに UIImageview があります。10秒ごとに画像を変えたいのですが、どうすればいいのかわかりません。

なにか提案を?

4

3 に答える 3

18

最初に画像の配列を作成します。

NSArray *images = [NSArray arrayWithObjects:[UIimage imagenamed:@"image1.png"],[UIimage imagenamed:@"image2.png"],[UIimage imagenamed:@"image3.png"],[UIimage imagenamed:@"image4.png"]]];

次に、配列をUIImageViewsの「animationImages」プロパティに設定します

imageView.animationImages = images;

アニメーションの時間を設定します。

imageView.animationDuration = 10;

アニメーションを開始..

[imageView startAnimating];

アニメーションを停止するには、これを行うだけです

[imageView stopAnimating];

ものすごく単純..

于 2012-04-29T09:41:33.430 に答える
4

タイマーを使用する必要があります。

NSTimer *timer = [NSTimer timerWithTimeInterval:10 target:self selector:@selector(changeImage) userInfo:nil repeats:true];

画像を変更するためのメソッドを実装します。

- (void) changeImage {
    imageView.image = newImage;
}

このタイマーをImageViewを含むViewControllerに入れるか、ImageViewをサブクラス化して、その画像自体を管理させることができます(特に、画像を変更する必要のある独立したimageviewがある場合に便利です)

于 2012-04-29T09:37:41.003 に答える