我为我的应用制作了一个简单的照片幻灯片,问题是我的代码在上一张图像之后不再重复图像!这是我的代码:

- (IBAction)start:(id)sender {

    _button.hidden = YES;
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(photoCounter) userInfo:nil repeats:YES];


}


- (void)photoCounter {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.90];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
    [self updatePhoto];
    imageCount ++;
    [UIView commitAnimations];

}

- (void)updatePhoto {

    switch (imageCount) {

        case 0:
            _images.image = [UIImage imageNamed:@"wall1.jpg"];
            break;

        case 1:
            _images.image = [UIImage imageNamed:@"wall2.jpg"];
            break;
        case 2:
            _images.image = [UIImage imageNamed:@"wall3.jpg"];
            break;
        case 3:
            _images.image = [UIImage imageNamed:@"wall4.jpg"];
            break;
        case 4:
            _images.image = [UIImage imageNamed:@"wall5.jpg"];
            break;

        default:
            break;
    }

}

最佳答案

从photoCounter方法中删除imageCount ++和

- (void)updatePhoto
{
    switch (imageCount)
    {
        case 0:
            _images.image = [UIImage imageNamed:@"wall1.jpg"];
            break;
        case 1:
            _images.image = [UIImage imageNamed:@"wall2.jpg"];
            break;
        case 2:
            _images.image = [UIImage imageNamed:@"wall3.jpg"];
            break;
        case 3:
            _images.image = [UIImage imageNamed:@"wall4.jpg"];
            break;
        case 4:
            _images.image = [UIImage imageNamed:@"wall5.jpg"];
            break;

        default:
            break;
    }
    imageCount ++;
    if (imageCount > 4)
        imageCount = 0;

}

10-08 07:46