Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-02-2011, 07:42 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 199
cinek is on a distinguished road
Default pageControl query

This is what I have so far for the pageControl. The only issue is that I need to specify what's loaded on a page in 2 places - I'm not sure if I'm doing this correctly. Right now it only works if I use the pageControl "buttons" at the bottom of the screen, swiping to the page doesn't do anything

.m file
Code:
static int kNumberOfPages = 2;

#import "MainViewViewController.h"

@implementation MainViewViewController
@synthesize scrollView, pageControl;


//Make sure the pageControl corresponds to the current page
-(void)scrollViewDidScroll:(UIScrollView *)sender{
    if(!pageControlUsed){
        //Switch the indicator when more than 50% of the previous or next page is visible
        CGFloat pageWidth = self.scrollView.frame.size.width;
        int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        self.pageControl.currentPage = page;
        
        if(page == 0){
            NSLog(@"its zero");
        } else if (page == 1){
            NSLog(@"its one");
        }
        
        [self loadPages];
    }
    
    
}

-(void)loadPages
{
    if (pageControl.currentPage == 1){
        NSLog(@"1");
    }
}

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

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

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


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    pageControl.currentPage = 1;
    
    [pageControl addTarget:self action:@selector(pageTurning:) forControlEvents:UIControlEventValueChanged];
    pageControlUsed = NO;
    
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * kNumberOfPages, self.scrollView.frame.size.height);
    
    scrollView.delegate = self;
    
    //Control pageControl
    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages = kNumberOfPages;
    
    
    
    // Do any additional setup after loading the view from its nib.
}
.h file

Code:
#import <UIKit/UIKit.h>

@interface MainViewViewController : UIViewController <UIScrollViewDelegate>
{
    IBOutlet UIScrollView *scrollView;
    IBOutlet UIPageControl *pageControl;
    BOOL pageControlUsed;
}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
cinek is offline   Reply With Quote
Old 12-02-2011, 12:02 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 199
cinek is on a distinguished road
Default

changed it around a bit, it now loads the view at page 0 - but when I swipe to change the page, the page number doesn't change, it stays at 0 ;/
cinek is offline   Reply With Quote
Old 12-02-2011, 01:14 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 199
cinek is on a distinguished road
Default

this is what I got now

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;
}
I think I need to call pageTurning in scrollViewDidScroll - but [self pageTurningageControl]; doesn't work.


Any ideas?
cinek is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 392
16 members and 376 guests
AppsBlogger, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, HemiMG, heshiming, iekei, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,913
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0