扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
使用UIPageViewController怎么实现左右滑动界面?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
10年积累的做网站、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有聊城免费网站建设让你可以放心的选择与我们合作。.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怎么实现左右滑动界面问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联网站建设公司行业资讯频道了解更多相关知识。
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流