Search code examples
iosanimationuiscrollviewuipagecontrol

UIScrollView + UIPageControl auto slide with animation


I use NSTimer to do the auto slide and my code is like this:

            NSTimer *timer;
            timer = [NSTimer scheduledTimerWithTimeInterval: 5
                                                     target: self
                                                   selector: @selector(handleTimer)
                                                   userInfo: nil
                                                    repeats: YES];
            - (void)handleTimer
            {
                int page = _bannerScrollView.contentOffset.x / 296;

                if ( page + 1 < [array count] )
                {
                    page++;
                    _pageControl.currentPage = page++;
                 }
                else 
                {
                    page = 0;
                    _pageControl.currentPage = page;
                }
                [self changePage];  
            }
            - (void)changePage
            {
                int page = _pageControl.currentPage;
                [_bannerScrollView setContentOffset:CGPointMake(296 * page, 0)];
            }

And I need some animation stuff, because it is cool. How can I do this? Thank you very much.


Solution

  • You can set frames according to ur needs and it will animate to next view with page control

     [scrollview scrollRectToVisible:CGRectMake(320,  80,320, 350) animated:YES];