大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
使用UIPageViewController怎么实现左右滑动界面?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
专注于为中小企业提供成都网站设计、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业黄平免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
.h
#import@interface ViewController : UIViewController @end
.m
#import "ViewController.h" #import "SubPage1ViewController.h" #import "SubPage2ViewController.h" @interface ViewController ()@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; }
关于使用UIPageViewController怎么实现左右滑动界面问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。