我有以下代码的问题。
如果我使用这些代码并在模拟器上运行它,他只会向我显示数组中带有过渡的前两张图片。如果我在 Iphone 上运行它,他只显示第一张照片。 他也不重复这些照片。-
我做错了什么?
- (void)viewDidLoad{
[super viewDidLoad];
welcomePhoto = [NSArray arrayWithObjects:@"Bild.jpeg",@"Bild1.jpeg", @"Bild2.png", nil];
imageView.image = [UIImage imageNamed:[welcomePhoto objectAtIndex:0]];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES];
}
-(void)transitionPhotos{
int photoCount;
if (photoCount < [welcomePhoto count] - 1){
photoCount ++;
}else{
photoCount = 0;
}
[UIView transitionWithView:self.imageView
duration:2.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{ imageView.image = [UIImage imageNamed:[welcomePhoto objectAtIndex:photoCount]]; }
completion:NULL];
}
最佳答案
尝试在 viewDidLoad 中添加它。
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 90, 100, 100)];
[self.view addSubview:animatedImageView];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"bild.png"],
[UIImage imageNamed:@"bild.png"],
[UIImage imageNamed:@"bild.png"], nil]; //etc
animatedImageView.animationDuration = 3.0f * [animatedImageView.animationImages count];
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];
关于ios - Iphone 上的幻灯片和过渡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299440/