• 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];
        }
    }
    
  • 相关阅读:
    POJ 1436 Horizontally Visible Segments (线段树+区间覆盖)
    HDU 4671 Backup Plan (构造)
    POJ 3325 Help with Intervals (线段树(难))
    HDU 4649 Professor Tian (位运算 + 按位DP)
    HDU 4662 MU Puzzle (YY+枚举)
    HDU 4638 Group (线段树 + 离线)
    深入浅出Node.js (附录A)
    JS的变量声明和函数声明提升
    JS基础:翻转数组
    JS基础:求一组数中的最大最小值,以及所在位置
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/7986148.html
Copyright © 2020-2023  润新知