• 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];
        }
    }
    
  • 相关阅读:
    西门子SCL读写DB数据
    LeetCode8.字符串转换整数(atoi) JavaScript
    LeetCode8.字符串转换整数(atoi) JavaScript
    WebRequestSugar
    iosblock用法
    datasci
    UINavigationController学习笔记
    iOSTab bar
    自定义tab bar控件 学习资料
    Ios tab Bar 使用方法
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/7986148.html
Copyright © 2020-2023  润新知