开发者

How to open image files using one view?

I can't seem to find any code online to switch views auto开发者_StackOverflowmatically. But I want my images to open automatically in a view one after another. Any advise?


I would like to open the image individually in each view, and kill the previous view when viewing the current view. I do not wish to use any slideshow. Hope you guys can advise me.


Add this line to viewDidLoad(This one is for the situation when you have your images stored in document directory of your project Dynamic):

    slideShowTimer=[NSTimer scheduledTimerWithTimeInterval: 3.0 target: self selector:@selector(changeImageSlide) userInfo: nil repeats:YES];

the changeImageSlide method:

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

OR

use the following(it's for the situation when your images are in the resource folder of your project and you have added them to your project static):

//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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜