首页 > 代码库 > 导航视图(二)
导航视图(二)
UIPageViewController 分屏效果笔记,参考IOS开发指南。
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIPageViewControllerDataSource, UIPageViewControllerDelegate>{ int pageIndex;}@property(strong, nonatomic) UIPageViewController *pageViewController;@end
@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.frame = CGRectMake(0.0f, 0.0f, 300.0f, 400.0f); // UIPageViewControllerTransitionStylePageCurl 翻书效果 // UIPageViewControllerTransitionStyleScroll 滑屏效果 // UIPageViewControllerNavigationOrientationHorizontal 水平方向 // UIPageViewControllerNavigationOrientationVertical 垂直方向 self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; self.pageViewController.dataSource = self; self.pageViewController.delegate = self; UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *page0 = [mainBoard instantiateViewControllerWithIdentifier:@"page1"]; NSArray *viewArray = @[page0]; [self.pageViewController setViewControllers:viewArray direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL]; [self.view addSubview:self.pageViewController.view]; pageIndex = 1; }-(UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{ pageIndex++; if(pageIndex > 2){ pageIndex = 2; return nil; } UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; NSString *Id = [NSString stringWithFormat:@"page%i", pageIndex]; NSLog(@"%@", Id); UIViewController *page = [mainBoard instantiateViewControllerWithIdentifier:Id]; return page;}-(UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{ pageIndex--; if(pageIndex < 0){ pageIndex = 0; return nil; } UIStoryboard *mainBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; NSString *Id = [NSString stringWithFormat:@"page%i", pageIndex]; NSLog(@"%@", Id); UIViewController *page = [mainBoard instantiateViewControllerWithIdentifier:Id]; return page;}@end
导航视图(二)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。