我似乎无法在线找到任何自动切换视图的代码。但我希望我的图像能够在一个接一个的视图中自动打开。有什么建议吗?
我想在每个视图中单独打开图像,并在查看当前视图时终止上一个视图。我不想使用任何幻灯片。希望你们能告诉我。
答案 0 :(得分:2)
将此行添加到viewDidLoad(这是针对您的图像存储在项目的文档目录中的情况动态):
slideShowTimer=[NSTimer scheduledTimerWithTimeInterval: 3.0 target: self selector:@selector(changeImageSlide) userInfo: nil repeats:YES];
changeImageSlide
方法:
- (void) changeImageSlide
{
totalNoOfImages=[copyOf_myGlobleArrayOfImageIds count];
if (imageCounter>=totalNoOfImages-1)
{
imageCounter=0;
}
NSString *str = [NSString stringWithFormat:@"%@.jpg",[copyOf_myGlobleArrayOfImageIds objectAtIndex:imageCounter]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullImgNm=[documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:str]];
//=(3*imageCounter+4)%25;
[mainSlideShowImageView setImage:[UIImage imageWithContentsOfFile:fullImgNm]];
[mainSlideShowImageView setTag:[[copyOf_myGlobleArrayOfImageIds objectAtIndex:imageCounter] intValue]];
imageCounter++;
}
使用以下内容(当您的图片位于项目的资源文件夹中并且已将它们添加到项目静态时):
//MAIN SIDE SHOW TASK
//while fetching names from database need to impliment another mutable array ref:information provider
NSArray *imageNames=[[NSArray alloc] initWithObjects:@"1.jpg",
@"2.jpg",
@"3.jpg",
@"4.jpg",
@"5.jpg",
@"6.jpg",
@"7.jpg",
@"8.jpg",
@"9.jpg",
@"10.jpg",
@"11.jpg",
@"12.jpg",
@"13.jpg",
@"14.jpg",
@"15.jpg",nil];
int limit=[imageNames count];
NSMutableArray *tempNames=[[NSMutableArray alloc] init];
for (int i=0; i<limit; i++) {
NSString *str= [NSString stringWithFormat:@"%@",[imageNames objectAtIndex:i]];
[tempNames addObject:[UIImage imageNamed:(NSString *)str]];
}
NSArray *images=tempNames;
NSLog(@"name array=======%@",images);
mainSlideShowImageView.animationImages=images;
mainSlideShowImageView.animationDuration = 75.00;
mainSlideShowImageView.animationRepeatCount = 0; //infinite
[mainSlideShowImageView startAnimating];
//MAIN SlIDE SHOW TASK COMPLETE