2011-08-01 72 views
0

我似乎無法在網上找到任何代碼來自動切換視圖。但我希望我的圖像能夠在一個接一個的視圖中自動打開。有任何建議嗎?如何使用一個視圖打開圖像文件?


我想在每個視圖中單獨打開圖像,並在查看當前視圖時關閉以前的視圖。我不希望使用任何幻燈片。希望你們能爲我提供建議。

+0

不要ü要創建幻燈片式...? – Hadi

+0

http://stackoverflow.com/questions/1631170/iphone-image-slideshow在這個鏈接,你會得到所有的東西。 – ram

回答

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++; 
} 

使用以下內容(適用於您的圖像位於您的pr資源文件夾中的情況oject和您將他們添加到您的項目靜態):

//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 
相關問題