我正在该应用程序中开发一个应用程序,从 NSArray 获取图像并将其存储到 ImageView 中,图像视图垂直滚动,每个页面都有一个图像。
我想在应用程序每次启动时显示随机图像。所有图像每次都会随机播放。
我试过这个。
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 490)];
[scrollView setPagingEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:NO];
NSArray *imageArray=[[NSArray alloc]initWithObjects:@"image1",@"image2",@"image3",@"image4",@"image5", nil];
for( i=0; i< [imageArray count];i++)
{
int i=arc4random()%[imageArray count]; // For Shuffle the images
NSString *imageName=[imageArray objectAtIndex:i];
NSString *fullImageName=[NSString stringWithFormat:@"%@.jpeg",imageName];
int padding=25;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*i+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
UIImageView *imageView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[imageView setImage:[UIImage imageNamed:fullImageName]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[scrollView addSubview:imageView];
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[imageArray count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
图像显示正确但不会随机更改。提前帮我解决这个问题。