0

自動変更画像ギャラリーを実装したい。これがコントローラーの私のコードです。image という名前の uiimageview があります。画像の配列を画像ビューにリンクして、数秒後に自動変更したいと考えています。私は何をすべきか??

- (void)viewDidLoad{
     [super viewDidLoad];
     [self performSelector:@selector(changeImage) withObject:nil afterDelay:2];
}

-(void)changeImage {
     NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"animated-fish-1.jpg"], [UIImage imageNamed:@"tumblr_7"], [UIImage imageNamed:@"th_nature_4.jpg"],nil];
     image.animationImages = images; 
     // how to let the array of image load and link to the perform selector??
     // what should i continue from here?
 }
4

4 に答える 4

1

タイマーを使用して画像をアニメーション化するには、これを試してください

- (void)viewDidLoad
{
        [super viewDidLoad];
        [NSTimer scheduledTimerWithTimeInterval:1 
                                 target:self 
                               selector:@selector(animateImages) 
                               userInfo:nil 
                                repeats:YES];
        imageCount = 1;

 }

  -(void)animateImages
  {
         imageCount = imageCount + 1;
          NSString *imageName = [NSString stringWithFormat:@"image%i.png"];
          [theImage setImage:[UIImage imageNamed:imageName]];
    }
于 2013-04-04T08:56:43.310 に答える
0

NSTimer を使用する必要があります。たとえば、次のメソッドを使用できます。

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/occ/clm/NSTimer/scheduledTimerWithTimeInterval:target:selector:userInfo:繰り返す:

このメソッドを使用すると、使用するセレクターを定義でき、x 秒ごとに繰り返すことができます

于 2013-04-04T08:51:27.097 に答える