2

I'm new here and could use some help, i'm making an ios app for the ipad and want to be able to animate the transition of pages in a pageview with custom and/or stock transitions.

What is the correct way to animate through various pages (PageView) each having full screen photos in them? Similar to in apples photos app. I'd like to be able to set up a basic slideshow and transition through them.

All Help is appreciated.

Thank You

Edit: Wow those responses were fast, is it also possible to have custom animations?

dt33
  • 73
  • 6

1 Answers1

4

you can create like this way:-

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScrollView *scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scr.tag = 1;
    scr.autoresizingMask=UIViewAutoresizingNone;
    [self.view addSubview:scr];
    [self setupScrollView:scr];
    UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 264, 480, 36)];
    [pgCtr setTag:12];
    pgCtr.numberOfPages=10;
    pgCtr.autoresizingMask=UIViewAutoresizingNone;
    [self.view addSubview:pgCtr];
}

- (void)setupScrollView:(UIScrollView*)scrMain {
    // we have 10 images here.
    // we will add all images into a scrollView & set the appropriate size.

    for (int i=1; i<=10; i++) {
        // create image
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"sti%02i.jpeg",i]];
        // create imageView
        UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake((i-1)*scrMain.frame.size.width, 0, scrMain.frame.size.width, scrMain.frame.size.height)];
        // set scale to fill
        imgV.contentMode=UIViewContentModeScaleToFill;
        // set image
        [imgV setImage:image];
        // apply tag to access in future
        imgV.tag=i+1;
        // add to scrollView
        [scrMain addSubview:imgV];
    }
    // set the content size to 10 image width
    [scrMain setContentSize:CGSizeMake(scrMain.frame.size.width*10, scrMain.frame.size.height)];
    // enable timer after each 2 seconds for scrolling.
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(scrollingTimer) userInfo:nil repeats:YES];
}

- (void)scrollingTimer {
    // access the scroll view with the tag
    UIScrollView *scrMain = (UIScrollView*) [self.view viewWithTag:1];
    // same way, access pagecontroll access
    UIPageControl *pgCtr = (UIPageControl*) [self.view viewWithTag:12];
    // get the current offset ( which page is being displayed )
    CGFloat contentOffset = scrMain.contentOffset.x;
    // calculate next page to display
    int nextPage = (int)(contentOffset/scrMain.frame.size.width) + 1 ;
    // if page is not 10, display it
    if( nextPage!=10 )  {
        [scrMain scrollRectToVisible:CGRectMake(nextPage*scrMain.frame.size.width, 0, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
        pgCtr.currentPage=nextPage;
    // else start sliding form 1 :)
    } else {
        [scrMain scrollRectToVisible:CGRectMake(0, 0, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
        pgCtr.currentPage=0;
    }
}

You can use:-

SDWebimage

AFNetworking

NSCache and use of NSCache

For image cache and asynchronous load image

UPDATE:-

Here Bellow is some Library that doing something like photo gallery slide show check this and if you want then use in to you project by reading How to Implement.

MWPhotoBrowser for iOS

EGOPhotoViewer for iOS

CXPhotoBrowser for iOS

FGallery for iOS

Nimbus for iOS

PTImageAlbumViewController for iOS

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • 1
    Wow! thanks, ill look through it, would you also say that I should be using some kind of cache method for as well or no because I know when I will be changing images? – dt33 Sep 14 '13 at 05:00
  • you welcome i attach some library for doing this task easily manage them self if you want then implement in to you code easy by reading Github how to use instruction. thank you – Nitin Gohel Sep 14 '13 at 05:24
  • CXPhotoBrowser: Sometimes pictures get stuck when browsing. If you open the photo to full screen (double click with your finger), then navigated to another photo. Has anyone encountered this problem? – Evgeny Fedin Jun 05 '15 at 13:35
  • better to put open new issue on Git-hub repository so author of this repository can fix this issue and give you solution. – Nitin Gohel Jun 05 '15 at 13:37