m文件幻灯片查看我的照片,我有8个但是在运行程序时它会跳过1号图片并从2 pic.how开始做正确的事
- (void)viewDidLoad
{
[super viewDidLoad];
imageId=0;
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
}
-(void)changeImage
{
imageId = imageId + 1;
CATransition * trs = [CATransition animation];
trs.duration = 1;
[trs setType:kCATransitionPush];
int id = imageId % NUMBER_OF_IMAGES;
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", id]];
[imageView.layer addAnimation:trs forKey:kCATransition];
}
答案 0 :(得分:0)
如Chris所述,您在加载图像时会增加图像编号。 只需将增量线移动到方法的末尾:
-(void)changeImage {
// imageId = imageId + 1;
CATransition * trs = [CATransition animation];
trs.duration = 1;
[trs setType:kCATransitionPush];
int id = imageId % NUMBER_OF_IMAGES;
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", id]];
[imageView.layer addAnimation:trs forKey:kCATransition];
imageId++;
}