• After more than 15 years covering everything Apple, it’s with a heavy heart we announce that we will no longer be publishing new content on iMore and the iMore forums will be closing as of November 1st, 2024.

help with page control

cinek

Member
May 30, 2010
15
0
0
Visit site
I'm trying to get pagecontrol to work. Right now I can scroll to the 2nd page, but the background is not changing (im changing the background to make sure it works fine). When I use pageControl to flip through pages, the background changes fine. I think I need to call pageTurning in scrollViewDidScroll but adding [self pageTurning:page]; does not work

this is what I have atm:

Code:
static int kNumberOfPages = 2;

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize pageControl, scrollView, viewControllers;

-(IBAction)changePage:(id)sender
{
    pageControlUsed = YES;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    pageControlUsed = NO;
}

-(void)scrollViewDidScroll:(UIScrollView *)sender
{
    if(pageControlUsed){
        return;
    }
    
    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2)/pageWidth) + 1;
    pageControl.currentPage = page;
    
}

-(void)pageTurning:(UIPageControl *)pageController{
    NSInteger nextPage = [pageController currentPage];
    
    switch (nextPage) {
        case 0:
            scrollView.backgroundColor = [UIColor blueColor];
            break;
        case 1:
            scrollView.backgroundColor = [UIColor redColor];
            
        default:
            break;
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
    scrollView.delegate = self;
    
    [pageControl addTarget:self action:@selector(pageTurning:) forControlEvents:UIControlEventValueChanged];
    
    pageControl.currentPage = 0;
    
    [self pageTurning:pageControl];
    
    //self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    //self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;

any ideas?
 

Latest posts

Trending Posts

Forum statistics

Threads
262,087
Messages
1,774,037
Members
441,393
Latest member
sunnyville01