UIPageViewController实现的左右滑动界面
更新时间:2018年06月30日 13:04:59 作者:Ittttttttta
这篇文章主要为大家详细介绍了UIPageViewController实现的左右滑动界面,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了UIPageViewController实现左右滑动界面展示的具体代码,供大家参考,具体内容如下
.h
#import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
.m
#import "ViewController.h" #import "SubPage1ViewController.h" #import "SubPage2ViewController.h" @interface ViewController ()<UIPageViewControllerDataSource,UIPageViewControllerDelegate> @property NSArray *contentViewControllers; //ViewControllers @property (nonatomic, strong) UIPageViewController *pageViewController; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self pageViewController]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark #pragma mark ----- UIPageViewControllerDataSource ----- - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger index = [self indexForViewController:viewController]; if (index == 0) { index = [self.contentViewControllers count] - 1; } else { index--; } return [self viewControllerAtIndex:index]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger index = [self indexForViewController:viewController]; index++; if (index == [self.contentViewControllers count]) { index = 0; } return [self viewControllerAtIndex:index]; } - (NSUInteger)indexForViewController:(UIViewController *)viewController { return [self.contentViewControllers indexOfObject:viewController]; } - (UIViewController *)viewControllerAtIndex:(NSUInteger)index { if (index > [self.contentViewControllers count]) { return nil; } UIViewController *vc = [self.contentViewControllers objectAtIndex:index]; return vc; } #pragma mark #pragma mark ----- UIPageViewControllerDelegate ----- - (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers { } - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed { } #pragma mark #pragma mark Init - (UIPageViewController *)pageViewController { if(!_pageViewController) { NSDictionary *options =[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey]; _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options]; [[_pageViewController view] setFrame:[[self view] bounds]]; _contentViewControllers = [NSMutableArray arrayWithObjects:[SubPage1ViewController new],[SubPage2ViewController new],nil]; // 设置UIPageViewController的配置项 [_pageViewController setViewControllers:[NSArray arrayWithObjects:_contentViewControllers[0], nil] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; _pageViewController.delegate = self; _pageViewController.dataSource = self; [self addChildViewController:self.pageViewController]; [self.view addSubview:self.pageViewController.view]; } return _pageViewController; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
iOS报Multiple commands produceMultiple错误的解决方案
这篇文章主要为大家介绍了iOS报Multiple commands produceMultiple错误的解决方案,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-11-11iOS App开发中通过UIDevice类获取设备信息的方法
UIDevice最常见的用法就是用来监测iOS设备的电量了,然后再实现电池状态通知非常方便,除此之外还有传感器等信息的获取,这里我们就来总结一下iOS App开发中通过UIDevice类获取设备信息的方法:2016-07-07
最新评论