码迷,mamicode.com
首页 > 其他好文 > 详细

导航视图(二)

时间:2016-10-07 20:19:53      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

UIPageViewController 分屏效果笔记,参考IOS开发指南。

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIPageViewControllerDataSource, UIPageViewControllerDelegate>
{
    int pageIndex;
}

@property(strong, nonatomic) UIPageViewController *pageViewController;


@end
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.frame = CGRectMake(0.0f, 0.0f, 300.0f, 400.0f);
    
    //  UIPageViewControllerTransitionStylePageCurl     翻书效果
    //  UIPageViewControllerTransitionStyleScroll       滑屏效果
    
    //  UIPageViewControllerNavigationOrientationHorizontal 水平方向
    //  UIPageViewControllerNavigationOrientationVertical   垂直方向
    self.pageViewController = [[UIPageViewController alloc]
                               initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    
    self.pageViewController.dataSource = self;
    self.pageViewController.delegate   = self;
    
    UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *page0 = [mainBoard instantiateViewControllerWithIdentifier:@"page1"];
    
    NSArray *viewArray = @[page0];
    
    
    [self.pageViewController setViewControllers:viewArray direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
    
    [self.view addSubview:self.pageViewController.view];
    
    pageIndex = 1;
    
}

-(UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    pageIndex++;
    
    if(pageIndex > 2){
        pageIndex = 2;
        return nil;
    }
    
    UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    NSString *Id = [NSString stringWithFormat:@"page%i", pageIndex];
    
    NSLog(@"%@", Id);
    
    UIViewController *page = [mainBoard instantiateViewControllerWithIdentifier:Id];
    
    return page;
}

-(UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    pageIndex--;
    
    if(pageIndex < 0){
        pageIndex = 0;
        return nil;
    }
    
    UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    NSString *Id = [NSString stringWithFormat:@"page%i", pageIndex];
    
    NSLog(@"%@", Id);
    
    UIViewController *page = [mainBoard instantiateViewControllerWithIdentifier:Id];
    
    return page;
}


@end

 

导航视图(二)

标签:

原文地址:http://www.cnblogs.com/Fredric-2013/p/5936477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!