UIPageViewController實(shí)現(xiàn)的左右滑動界面
更新時(shí)間:2018年06月30日 13:04:59 作者:Ittttttttta
這篇文章主要為大家詳細(xì)介紹了UIPageViewController實(shí)現(xiàn)的左右滑動界面,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了UIPageViewController實(shí)現(xiàn)左右滑動界面展示的具體代碼,供大家參考,具體內(nèi)容如下
.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]; // 設(shè)置UIPageViewController的配置項(xiàng) [_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; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- iOS使用pageViewController實(shí)現(xiàn)多視圖滑動切換
- iOS多控制器實(shí)現(xiàn)帶滑動動畫
- iOS左右滑動標(biāo)簽頁導(dǎo)航的設(shè)計(jì)
- IOS仿今日頭條滑動導(dǎo)航欄
- iOS滑動解鎖、滑動獲取驗(yàn)證碼效果的實(shí)現(xiàn)代碼
- ios scrollview嵌套tableview同向滑動的示例
- 微信瀏覽器彈出框滑動時(shí)頁面跟著滑動的實(shí)現(xiàn)代碼(兼容Android和IOS端)
- IOS開發(fā)中禁止NavigationController的向右滑動返回
- IOS開發(fā)向右滑動返回前一個(gè)頁面功能(demo)
- iOS實(shí)現(xiàn)雙向滑動條效果
相關(guān)文章
IOS 遠(yuǎn)程通知兼容(IOS7,IOS8)實(shí)例詳解
這篇文章主要介紹了IOS 遠(yuǎn)程通知兼容(IOS7,IOS8)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03iOS 使用Moya網(wǎng)絡(luò)請求的實(shí)現(xiàn)方法
這篇文章主要介紹了iOS 使用Moya網(wǎng)絡(luò)請求的實(shí)現(xiàn)方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07iOS報(bào)Multiple?commands?produceMultiple錯(cuò)誤的解決方案
這篇文章主要為大家介紹了iOS報(bào)Multiple?commands?produceMultiple錯(cuò)誤的解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法
UIDevice最常見的用法就是用來監(jiān)測iOS設(shè)備的電量了,然后再實(shí)現(xiàn)電池狀態(tài)通知非常方便,除此之外還有傳感器等信息的獲取,這里我們就來總結(jié)一下iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法:2016-07-07iOS 圖片上傳使用base64或者二進(jìn)制流上傳頭像功能
這篇文章主要介紹了iOS 圖片上傳使用base64或者二進(jìn)制流上傳頭像功能,需要的朋友可以參考下2017-09-09