zoukankan      html  css  js  c++  java
  • UIPageViewController基本使用

    UIPageViewController基本使用

    @interface ViewController ()<UIPageViewControllerDelegate,UIPageViewControllerDataSource>
    
    @property(nonatomic,strong)UIPageViewController *pageVC;
    @property(nonatomic,strong)NSMutableArray *dataArr;
    @end
    
    @implementation ViewController
    
    -(NSMutableArray *)dataArr{
        if(!_dataArr){
            _dataArr = [NSMutableArray array];
            [_dataArr addObject:[MyViewController new]];
            [_dataArr addObject:[MyViewController new]];
            [_dataArr addObject:[MyViewController new]];
        }
        return _dataArr;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.pageVC.view.bounds = CGRectMake(0, 0,SCREEN_WIDTH, SCREEN_HEIGHT);
        
    }
    -(UIPageViewController *)pageVC{
        if(!_pageVC){
            _pageVC = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
            _pageVC.delegate = self;
            
            _pageVC.dataSource = self;
            
            [self addChildViewController:_pageVC];
            [self.view addSubview:_pageVC.view];
            [_pageVC didMoveToParentViewController:self];
            [_pageVC setViewControllers:@[self.dataArr[0]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
        }
        return _pageVC;
    }
    #pragma mark UIPageViewControllerDelegate
    - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed{
       
    }
    
    #pragma mark UIPageViewControllerDataSource
    - (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
        NSInteger currentPage = [self.dataArr indexOfObject:viewController];
        if(currentPage <= 0){
            return  nil;
        }else{
            currentPage --;
            return self.dataArr[currentPage];
        }
    }
    - (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
        NSInteger currentPage = [self.dataArr indexOfObject:viewController];
    
        if(currentPage >= self.dataArr.count - 1){
            return  nil;
        }else{
            currentPage ++;
            return self.dataArr[currentPage];
        }
    }
    
  • 相关阅读:
    归并之将两个有序数组合并(已測试)
    Embedded Android 协同翻译
    IOS中公布应用程序,进度条一直不走怎么处理
    《textanalytics》课程简单总结(2):topic mining
    编程小错误备忘录
    观察者模式
    scrapy递归抓取网页数据
    leetCode 95.Unique Binary Search Trees II (唯一二叉搜索树) 解题思路和方法
    spring4.0.0的配置和使用
    ios面试基础
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/7986148.html
Copyright © 2011-2022 走看看