0

この乱数で画像がスクロールされます..そして画像を停止します..ここで私のコードでは、最初の乱数が生成され、nに保存されます.. ランダムなnoは12を生成し、次に12回画像がスクロールされ、その後停止します..

- (void)viewDidLoad
{
int n = 1 + arc4random() % 10 + 10;

    NSString *string = [NSString stringWithFormat:@"%i",n];

    //lbl.text = string;

    NSUInteger i;
    for (i = 1; i <= kNumImages; i++)
    {


       // [kNumImages addObject:[NSNumber numberWithInt:i]];
        NSString *imageName = [NSString stringWithFormat:@"%d.png", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        CGRect rect = imageView.frame;
        rect.size.height = kScrollObjHeight;
        rect.size.width = kScrollObjWidth;
        imageView.frame = rect;
        imageView.tag = i;  
        lbl.text = string;
        [FirstScrollView addSubview:imageView];
        [imageView release];

        if(n == i){
          break;       

    }

}

ランダムな no が一致する場合にスクロールを停止したいのですが、n == iどうすればそれを行うことができますか?

4

2 に答える 2

0

これを試して、

- (void)viewDidLoad
{
int n = 1 + arc4random() % 10 + 10;

    NSString *string = [NSString stringWithFormat:@"%i",n];

    //lbl.text = string;

    NSUInteger i;
    for (i = 1; i <= kNumImages; i++)
    {
        if(n == i)
          break;
        else {

       // [kNumImages addObject:[NSNumber numberWithInt:i]];
        NSString *imageName = [NSString stringWithFormat:@"%d.png", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        CGRect rect = imageView.frame;
        rect.size.height = kScrollObjHeight;
        rect.size.width = kScrollObjWidth;
        imageView.frame = rect;
        imageView.tag = i;  
        lbl.text = string;
        [FirstScrollView addSubview:imageView];
        [imageView release];

          }    

    }

}
于 2012-10-29T06:06:17.053 に答える
0

[firstScrollView setContentOffset:CGRectMake(n*firstScrollView.frame.size.width,firstScrollView.frame.size.height)];

必要なのは、scrollView のコンテンツ オフセットを設定することだけです。

于 2012-10-29T06:18:36.720 に答える